Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/mobile: Fails on FreeBSD #16989

Closed
rwestlund opened this issue Sep 4, 2016 · 5 comments
Closed

x/mobile: Fails on FreeBSD #16989

rwestlund opened this issue Sep 4, 2016 · 5 comments
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile
Milestone

Comments

@rwestlund
Copy link

gomobile init fails on FreeBSD when fetching NDK.

./bin/gomobile: error fetching https://dl.google.com/go/mobile/gomobile-ndk-r12b-freebsd-x86_64.tar.gz, status: 404 Not Found

Looks like there isn't a FreeBSD build. I can't find any instructions for manually doing what gomobile init is doing.

Version:

go version go1.6.2 freebsd/amd64

Env:

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="freebsd"
GOOS="freebsd"
GOPATH="/usr/home/randy/code/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/freebsd_amd64"
GO15VENDOREXPERIMENT="1"
CC="cc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="clang++"
CGO_ENABLED="1"
@minux
Copy link
Member

minux commented Sep 4, 2016 via email

@rwestlund
Copy link
Author

I looked into it more and you're right. However, the Linux version should work under FreeBSD's Linux compatibility layer; FreeBSD provides a full Linux userland. When I set goos = "linux" to make it download the Linux version, I get this error:

randy@mako ~/c/go> ./bin/gomobile init
ELF interpreter /lib64/ld-linux-x86-64.so.2 not found, error 2
./bin/gomobile: go install -gcflags=-shared -ldflags=-shared -pkgdir=/usr/home/randy/code/go/pkg/gomobile/pkg_android_amd64 std failed: exit status 1
go build runtime/cgo: /usr/local/go/pkg/tool/freebsd_amd64/cgo: exit status 2

/lib64/ld-linux-x86-64.so.2 is not the right path on FreeBSD. Let me see whether I can get this working.

@quentinmit quentinmit added this to the Unreleased milestone Sep 6, 2016
@rwestlund
Copy link
Author

I have gomobile working on FreeBSD with the following small patch. The Linux version of NDK works under FreeBSD's Linux emulation layer.

--- init.go.orig        2016-09-07 22:25:25.972598863 -0400
+++ init.go     2016-09-07 22:26:26.739591760 -0400
@@ -402,6 +402,8 @@
                "android-%s/toolchains/llvm/prebuilt", ndkVersion))
        if goos == "windows" && ndkarch == "x86" {
                llvmsrc = filepath.Join(llvmsrc, "windows")
+    } else if goos == "freebsd" {
+               llvmsrc = filepath.Join(llvmsrc, "linux-"+ndkarch)
        } else {
                llvmsrc = filepath.Join(llvmsrc, goos+"-"+ndkarch)
        }
@@ -431,6 +433,8 @@
                        "android-%s/toolchains/%s/prebuilt", ndkVersion, toolchain.gcc))
                if goos == "windows" && ndkarch == "x86" {
                        ndkpath = filepath.Join(ndkpath, "windows")
+        } else if goos == "freebsd" {
+                       ndkpath = filepath.Join(ndkpath, "linux-"+ndkarch)
                } else {
                        ndkpath = filepath.Join(ndkpath, goos+"-"+ndkarch)
                }
@@ -467,7 +471,13 @@
 }

 func fetchStrippedNDK() error {
-       url := "https://dl.google.com/go/mobile/gomobile-" + ndkVersion + "-" + goos + "-" + ndkarch + ".tar.gz"
+    var url string;
+    // To support FreeBSD, use the Linux version under 64-bit linux emulation.
+    if goos == "freebsd" {
+           url = "https://dl.google.com/go/mobile/gomobile-" + ndkVersion + "-linux-" + ndkarch + ".tar.gz"
+    } else {
+           url = "https://dl.google.com/go/mobile/gomobile-" + ndkVersion + "-" + goos + "-" + ndkarch + ".tar.gz"
+    }
        archive, err := fetch(url)
        if err != nil {
                return err
@@ -476,7 +486,13 @@
 }

 func fetchFullNDK() error {
-       url := "https://dl.google.com/android/repository/android-" + ndkVersion + "-" + goos + "-" + ndkarch + ".zip"
+    // To support FreeBSD, use the Linux version under 64-bit linux emulation.
+    var url string;
+    if goos == "freebsd" {
+           url = "https://dl.google.com/android/repository/android-" + ndkVersion + "-linux-" + ndkarch + ".zip"
+    } else {
+           url = "https://dl.google.com/android/repository/android-" + ndkVersion + "-" + goos + "-" + ndkarch + ".zip"
+    }
        archive, err := fetch(url)
        if err != nil {
                return err

To run on FreeBSD with this patch:

  • Set DEFAULT_VERSIONS+=linux=c7_64 in /etc/make.conf
  • Install /usr/ports/emulation/linux_base-c7
  • Copy a libc++.so from a recent Linux repo into /compat/linux/lib64

The gomobile tool will now work as normal.

I've created a PR upstream for proper NDK support on FreeBSD. If that ever happens, this patch will not be necessary.
https://code.google.com/p/android/issues/detail?id=221683

@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Jul 20, 2017
@eliasnaur
Copy link
Contributor

Is this still a problem? Much has happened since this was reported. For example, gomobile doesn't download the NDK anymore.

@changkun
Copy link
Member

As previously discussed, gomobile does not download NDK anymore and the support for FreeBSD depends on the Android SDK on the platform itself. Close.

@golang golang locked and limited conversation to collaborators Mar 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge mobile Android, iOS, and x/mobile
Projects
None yet
Development

No branches or pull requests

6 participants