Skip to content

Commit fea317f

Browse files
changkunhajimehoshi
authored andcommitted
cmd/gomobile: use LLVM binutils if GNU binutils are missing
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>
1 parent d61a72f commit fea317f

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

cmd/gomobile/env.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"errors"
55
"fmt"
6+
"io/fs"
67
"io/ioutil"
78
"os"
89
"os/exec"
@@ -427,14 +428,23 @@ func (tc *ndkToolchain) ClangPrefix() string {
427428
}
428429

429430
func (tc *ndkToolchain) Path(ndkRoot, toolName string) string {
430-
var pref string
431+
cmdFromPref := func(pref string) string {
432+
return filepath.Join(ndkRoot, "toolchains", "llvm", "prebuilt", archNDK(), "bin", pref+"-"+toolName)
433+
}
434+
435+
var cmd string
431436
switch toolName {
432437
case "clang", "clang++":
433-
pref = tc.ClangPrefix()
438+
cmd = cmdFromPref(tc.ClangPrefix())
434439
default:
435-
pref = tc.toolPrefix
440+
cmd = cmdFromPref(tc.toolPrefix)
441+
// Starting from NDK 23, GNU binutils are fully migrated to LLVM binutils.
442+
// See https://android.googlesource.com/platform/ndk/+/master/docs/Roadmap.md#ndk-r23
443+
if _, err := os.Stat(cmd); errors.Is(err, fs.ErrNotExist) {
444+
cmd = cmdFromPref("llvm")
445+
}
436446
}
437-
return filepath.Join(ndkRoot, "toolchains", "llvm", "prebuilt", archNDK(), "bin", pref+"-"+toolName)
447+
return cmd
438448
}
439449

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

0 commit comments

Comments
 (0)