Closed nicokosi closed 2 months ago
No error after downgrading Go to 1.21
, see gh-collab-scanner 1.5.4.
I presume that it is a Go issue related to GitHub Actions Runner Images, but maybe that this issue can be kept open (using Go 1.21 instead of latest 1.22 is a work-around)? 🤷
Try with CGO_ENABLED=1
With CGO_ENABLED=1
:
gcc_android.c:6:10: fatal error: android/log.h: No such file or directory
6 | #include <android/log.h>
| ^~~~~~~~~~~~~~~
compilation terminated.
Go version: 1.22
Same error here. Since go v1.22 it requires cgo
for at least those platforms:
... maybe more
@nicokosi @Biswa96 @baruchiro @the-hotmann : firstly, thank you all for raising this issue and starting exploring the nuances. ❤
I'm currently looking into this issue to see how this changing behavior with Go 1.22 should be taken into account here 🙇
// MustLinkExternal reports whether goos/goarch requires external linking
// with or without cgo dependencies.
func MustLinkExternal(goos, goarch string, withCgo bool) bool {
if withCgo {
switch goarch {
case "loong64", "mips", "mipsle", "mips64", "mips64le":
// Internally linking cgo is incomplete on some architectures.
// https://go.dev/issue/14449
return true
case "arm64":
if goos == "windows" {
// windows/arm64 internal linking is not implemented.
return true
}
case "ppc64":
// Big Endian PPC64 cgo internal linking is not implemented for aix or linux.
// https://go.dev/issue/8912
if goos == "aix" || goos == "linux" {
return true
}
}
switch goos {
case "android":
return true
case "dragonfly":
// It seems that on Dragonfly thread local storage is
// set up by the dynamic linker, so internal cgo linking
// doesn't work. Test case is "go test runtime/cgo".
return true
}
}
switch goos {
case "android":
if goarch != "arm64" {
return true
}
case "ios":
if goarch == "arm64" {
return true
}
}
return false
}
Doing a bit of digging, one option I need to carve out a little more time to try comes from https://github.com/golang/go/issues/42725#issuecomment-731438285, which highlights the need to override CC
when compiling for android
to point to Android NDK which is maintained on GitHub-hosted runners:
GOOS=android GOARCH=arm64 CGO_ENABLED=1 CC=$NDK_ROOT/21.3.6528147/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android30-clang go build
This should live within $ANDROID_NDK_HOME
on GitHub-managed runners
- uses: nttld/setup-ndk@v1
id: setup-ndk
with:
ndk-version: r25b
add-to-path: true
- name: Build Golang lib
shell: bash
env:
ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
run: |
pushd clash
env GOOS=android GOARCH=arm64 CC=${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android29-clang GOARM=7 CGO_ENABLED=1 go build -buildmode=c-shared -o ./libclash.so
popd
mkdir -p ./android/app/src/main/jniLibs/arm64-v8a
${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip clash/libclash.so
mv clash/libclash.so ./android/app/src/main/jniLibs/arm64-v8a/libclash.so
- name: arm64-v8a Set environment variables
shell: bash
run: |
echo "CC=$(echo $ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android${RCLONE_NDK_VERSION}-clang)" >> $GITHUB_ENV
echo "CC_FOR_TARGET=$CC" >> $GITHUB_ENV
echo 'GOOS=android' >> $GITHUB_ENV
echo 'GOARCH=arm64' >> $GITHUB_ENV
echo 'CGO_ENABLED=1' >> $GITHUB_ENV
echo 'CGO_LDFLAGS=-fuse-ld=lld -s -w' >> $GITHUB_ENV
- name: arm64-v8a build
run: go build -v -tags android -trimpath -ldflags '-s -X github.com/rclone/rclone/fs.Version='${VERSION} -o build/rclone-android-${RCLONE_NDK_VERSION}-armv8a .
- name: Build android/arm64 Client w/ DNS Fix
env:
BUILD_VERSION: ${{ steps.get_version.outputs.VERSION }}
run: |
CC=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android28-clang CXX=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android28-clang++ CGO_ENABLED=1 GOARCH=arm64 GOOS=android go build -tags 'osusergo netgo' -ldflags "-X 'main.Version=$BUILD_VERSION' -s -w -extldflags -static" -a -o bin/t-client-android-arm64 ./cmd/client
For what it's worth, I've been able to work around this problem by forking the action and removing Android build targets from build_and_release.sh
:
platforms=(
darwin-amd64
darwin-arm64
freebsd-386
freebsd-amd64
freebsd-arm64
linux-386
linux-amd64
linux-arm
linux-arm64
windows-386
windows-amd64
windows-arm64
)
I'm uninformed regarding the rationale for maintaining Android as a build target for CLI extensions in the first place. In our case, we decided that the accessibility of recent Go versions was more important than maintaining support for a build target we expect to be used rarely (if ever) by the end users of our particular extension.
Hello,
I cannot release nicokosi/gh-collab-scanner, cf. this GitHub Actions' job:
The last release that succeeded,
v1.5.3
:github.com/cli/go-gh
which has not been updated to v2 yet ;I tried several changes: enable CGO (not sure it is correct), use a Windows runner etc. but I could not make the release succeed (see the GitHub Actions build history).
Do you have any advice/tip? Thank you!