Skip to content

Commit

Permalink
cmd/gomobile: use LLVM binutils if GNU binutils are missing
Browse files Browse the repository at this point in the history
Starting from NDK 23, GNU binutils are fully migrated to LLVM binutils.
Use LLVM if GNU binutils are missing.

Fixes golang/go#49808

Change-Id: Iccb40780390a66081fc811d717c7357194b92acf
Reviewed-on: https://go-review.googlesource.com/c/mobile/+/369195
Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Hajime Hoshi <hajimehoshi@gmail.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
  • Loading branch information
changkun authored and hajimehoshi committed Dec 6, 2021
1 parent d61a72f commit fea317f
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions cmd/gomobile/env.go
Expand Up @@ -3,6 +3,7 @@ package main
import (
"errors"
"fmt"
"io/fs"
"io/ioutil"
"os"
"os/exec"
Expand Down Expand Up @@ -427,14 +428,23 @@ func (tc *ndkToolchain) ClangPrefix() string {
}

func (tc *ndkToolchain) Path(ndkRoot, toolName string) string {
var pref string
cmdFromPref := func(pref string) string {
return filepath.Join(ndkRoot, "toolchains", "llvm", "prebuilt", archNDK(), "bin", pref+"-"+toolName)
}

var cmd string
switch toolName {
case "clang", "clang++":
pref = tc.ClangPrefix()
cmd = cmdFromPref(tc.ClangPrefix())
default:
pref = tc.toolPrefix
cmd = cmdFromPref(tc.toolPrefix)
// Starting from NDK 23, GNU binutils are fully migrated to LLVM binutils.
// See https://android.googlesource.com/platform/ndk/+/master/docs/Roadmap.md#ndk-r23
if _, err := os.Stat(cmd); errors.Is(err, fs.ErrNotExist) {
cmd = cmdFromPref("llvm")
}
}
return filepath.Join(ndkRoot, "toolchains", "llvm", "prebuilt", archNDK(), "bin", pref+"-"+toolName)
return cmd
}

type ndkConfig map[string]ndkToolchain // map: GOOS->androidConfig.
Expand Down

0 comments on commit fea317f

Please sign in to comment.