From 8592fb7121874f7998e0df10c3c7e6777eb78033 Mon Sep 17 00:00:00 2001 From: Bagas Sanjaya Date: Sat, 11 Apr 2020 10:13:31 +0700 Subject: [PATCH] [Docs] Cross Build Gitea from Source (#10999) * Add cross-build docs Note that C cross compiler is required for building Gitea with `TAGS`. * Apply suggestion from @mrsdizzie Co-Authored-By: mrsdizzie * Apply suggestion from @guillep2k Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: Lunny Xiao Co-authored-by: mrsdizzie Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: John Olheiser --- .../doc/installation/from-source.en-us.md | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/content/doc/installation/from-source.en-us.md b/docs/content/doc/installation/from-source.en-us.md index 2089a5df39..d70e000352 100644 --- a/docs/content/doc/installation/from-source.en-us.md +++ b/docs/content/doc/installation/from-source.en-us.md @@ -157,3 +157,23 @@ Add as many of the strings with their preceding `-X` to the `LDFLAGS` variable a with the appropriate `TAGS` as above. Running `gitea help` will allow you to review what the computed settings will be for your `gitea`. + +## Cross Build + +The `go` compiler toolchain supports cross-compiling to different architecture targets that are supported by the toolchain. See [`GOOS` and `GOARCH` environment variable](https://golang.org/doc/install/source#environment) for the list of supported targets. Cross compilation is helpful if you want to build Gitea for less-powerful systems (such as Raspberry Pi). + +To cross build Gitea with build tags (`TAGS`), you also need a C cross compiler which targets the same architecture as selected by the `GOOS` and `GOARCH` variables. For example, to cross build for Linux ARM64 (`GOOS=linux` and `GOARCH=arm64`), you need the `aarch64-unknown-linux-gnu-gcc` cross compiler. This is required because Gitea build tags uses `cgo`'s foreign-function interface (FFI). + +Cross-build Gitea for Linux ARM64, without any tags: + +``` +GOOS=linux GOARCH=arm64 make build +``` + +Cross-build Gitea for Linux ARM64, with recommended build tags: + +``` +CC=aarch64-unknown-linux-gnu-gcc GOOS=linux GOARCH=arm64 TAGS="bindata sqlite sqlite_unlock_notify" make build +``` + +Replace `CC`, `GOOS`, and `GOARCH` as appropriate for your architecture target.