Skip to content

Commit

Permalink
Merge pull request #97 from anywherelan/linux-remove-cgo
Browse files Browse the repository at this point in the history
build: remove cgo dependency on all platforms
  • Loading branch information
pymq committed Jun 10, 2023
2 parents edb53b9 + 514b3d9 commit 52991f8
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 122 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build-manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
java-version: '12.x'
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.3.x'
flutter-version: '3.10.x'
channel: 'stable'
- run: flutter --version
- name: Install ndk-bundle
Expand All @@ -57,7 +57,6 @@ jobs:
gomobile init
go mod tidy -compat=1.20
cd cmd/awl-tray && go mod tidy -compat=1.20 && cd ../..
./build.sh docker-images
./build.sh release
echo "ls build"
ls -la build
Expand Down
2 changes: 0 additions & 2 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

* Go (1.20)
* Git
* Docker - only for cross-compilation of awl-tray for linux, do not need for development
* gcc, gtk3, libappindicator3 for awl-tray on Linux ([see more](https://github.com/anywherelan/systray#platform-notes))
- only for development, do not need for release build
* gomobile and Android Studio for Android ([see more](https://pkg.go.dev/golang.org/x/mobile/cmd/gomobile))
Expand All @@ -16,7 +15,6 @@ The first step is to clone [awl](https://github.com/anywherelan/awl) and [awl-fl

```bash
cd awl
./build.sh docker-images
./build.sh release
ls build
```
Expand Down
29 changes: 4 additions & 25 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ gobuild-linux() {
for arch in 386 amd64 arm arm64 mips mipsle; do
archive_name="$name-linux-$arch-$VERSION.tar.gz"
filename="$name"
GOOS=linux GOARCH=$arch go build -trimpath -ldflags "-s -w -X github.com/anywherelan/awl/config.Version=${VERSION}" -o "$filename"
CGO_ENABLED=0 GOOS=linux GOARCH=$arch go build -trimpath -ldflags "-s -w -X github.com/anywherelan/awl/config.Version=${VERSION}" -o "$filename"
tar -czf "$archive_name" "$filename"
rm "$filename"
mv "$archive_name" "$builddir"
Expand All @@ -71,7 +71,7 @@ gobuild-windows() {
install-wintun "$arch"
archive_name="$name-windows-$arch-$VERSION.zip"
filename="$name.exe"
GOOS=windows GOARCH=$arch go build -trimpath -ldflags "-s -w -H windowsgui -X github.com/anywherelan/awl/config.Version=${VERSION}" -o "$filename"
CGO_ENABLED=0 GOOS=windows GOARCH=$arch go build -trimpath -ldflags "-s -w -H windowsgui -X github.com/anywherelan/awl/config.Version=${VERSION}" -o "$filename"
zip "$archive_name" "$filename"
rm "$filename"
mv "$archive_name" "$builddir"
Expand Down Expand Up @@ -135,8 +135,8 @@ build-awl-cross() {
# build desktop version for windows and others OS
build-awl-tray-cross() {
cd "$awldir/cmd/awl-tray"
gobuild-linux awl-tray
gobuild-windows awl-tray
build-awl-tray-linux-cross
}

# build desktop version based on current environment
Expand All @@ -153,40 +153,22 @@ build-awl-tray() {
archive_name="$archive_name.tar.gz"
fi
cd "$awldir/cmd/awl-tray"
go build -trimpath -ldflags "-s -w -X github.com/anywherelan/awl/config.Version=${VERSION}" -o "$filename"
# set host's rights because when build from docker it will be root:root
host_uid="$(stat -c "%u" "$builddir")"
host_gid="$(stat -c "%g" "$builddir")"
chown "$host_uid:$host_gid" "$filename"
CGO_ENABLED=0 go build -trimpath -ldflags "-s -w -X github.com/anywherelan/awl/config.Version=${VERSION}" -o "$filename"
if [ "$goos" == "windows" ]; then
zip "$archive_name" "$filename"
elif [ "$goos" == "linux" ]; then
tar -czf "$archive_name" "$filename"
fi
chown "$host_uid:$host_gid" "$archive_name"
rm "$filename"
mv "$archive_name" "$builddir"
}

build-awl-tray-linux-cross() {
cd "$awldir"
for arch in 386 amd64 arm arm64; do
docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp "awl-cross-$arch" /bin/sh -c './build.sh awl-tray'
done
}

# build server and desktop versions
build-desktop-cross() {
build-awl-cross
build-awl-tray-cross
}

build-docker-images() {
for arch in 386 amd64 arm arm64; do
docker build -t "awl-cross-$arch" "./crosscompile/linux-$arch"
done
}

case "${1:-default}" in
release)
clean
Expand All @@ -208,9 +190,6 @@ awl-tray)
download-wintun
build-awl-tray
;;
docker-images)
build-docker-images
;;
deps)
download-wintun
install-wintun "$(go env GOARCH)"
Expand Down
23 changes: 0 additions & 23 deletions crosscompile/linux-386/Dockerfile

This file was deleted.

20 changes: 0 additions & 20 deletions crosscompile/linux-amd64/Dockerfile

This file was deleted.

25 changes: 0 additions & 25 deletions crosscompile/linux-arm/Dockerfile

This file was deleted.

25 changes: 0 additions & 25 deletions crosscompile/linux-arm64/Dockerfile

This file was deleted.

0 comments on commit 52991f8

Please sign in to comment.