Skip to content

Commit 167ebed

Browse files
committed
cmd/gomobile: require NDK r19c and delete workaround for NDK r19b
The prebuilt toolchains introduced in NDK r19b didn't work on Windows. NDK r19c contains a fix, so remove our workaround and check for r19c on Windows. Change-Id: I3bcfedbc156f10c3cab8e74dcbd7de68575669e7 Reviewed-on: https://go-review.googlesource.com/c/mobile/+/168067 TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 9487ef5 commit 167ebed

File tree

1 file changed

+14
-33
lines changed

1 file changed

+14
-33
lines changed

cmd/gomobile/env.go

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"errors"
55
"fmt"
66
"io/ioutil"
7-
"log"
87
"os"
98
"os/exec"
109
"path/filepath"
@@ -86,17 +85,27 @@ func envInit() (err error) {
8685
androidEnv = make(map[string][]string)
8786
for arch, toolchain := range ndk {
8887
clang := toolchain.Path(ndkRoot, "clang")
88+
clangpp := toolchain.Path(ndkRoot, "clang++")
8989
if !buildN {
90-
_, err = os.Stat(clang)
91-
if err != nil {
92-
return fmt.Errorf("No compiler for %s was found in the NDK (tried %q). Make sure your NDK version is >= r19b. Use `sdkmanager --update` to update it.", arch, clang)
90+
tools := []string{clang, clangpp}
91+
if runtime.GOOS == "windows" {
92+
// Because of https://github.com/android-ndk/ndk/issues/920,
93+
// we require r19c, not just r19b. Fortunately, the clang++.cmd
94+
// script only exists in r19c.
95+
tools = append(tools, clangpp+".cmd")
96+
}
97+
for _, tool := range tools {
98+
_, err = os.Stat(tool)
99+
if err != nil {
100+
return fmt.Errorf("No compiler for %s was found in the NDK (tried %s). Make sure your NDK version is >= r19c. Use `sdkmanager --update` to update it.", arch, tool)
101+
}
93102
}
94103
}
95104
androidEnv[arch] = []string{
96105
"GOOS=android",
97106
"GOARCH=" + arch,
98107
"CC=" + clang,
99-
"CXX=" + toolchain.Path(ndkRoot, "clang++"),
108+
"CXX=" + clangpp,
100109
"CGO_ENABLED=1",
101110
}
102111
if arch == "arm" {
@@ -273,41 +282,13 @@ func (tc *ndkToolchain) Path(ndkRoot, toolName string) string {
273282
var pref string
274283
switch toolName {
275284
case "clang", "clang++":
276-
if runtime.GOOS == "windows" {
277-
return tc.createNDKr19bWorkaroundTool(ndkRoot, toolName)
278-
}
279285
pref = tc.clangPrefix
280286
default:
281287
pref = tc.toolPrefix
282288
}
283289
return filepath.Join(ndkRoot, "toolchains", "llvm", "prebuilt", archNDK(), "bin", pref+"-"+toolName)
284290
}
285291

286-
// createNDKr19bWorkaroundTool creates a Windows wrapper script for clang or clang++.
287-
// The scripts included in r19b are broken on Windows: https://github.com/android-ndk/ndk/issues/920.
288-
// TODO: Remove this when r19c is out; the code inside is hacky and panicky.
289-
func (tc *ndkToolchain) createNDKr19bWorkaroundTool(ndkRoot, toolName string) string {
290-
toolCmd := filepath.Join(tmpdir, fmt.Sprintf("%s-%s.cmd", tc.arch, toolName))
291-
tool, err := os.Create(toolCmd)
292-
if err != nil {
293-
log.Fatal(err)
294-
}
295-
defer func() {
296-
if err := tool.Close(); err != nil {
297-
log.Fatal(err)
298-
}
299-
}()
300-
tcBin := filepath.Join(ndkRoot, "toolchains", "llvm", "prebuilt", archNDK(), "bin")
301-
// Adapted from the NDK cmd wrappers.
302-
toolCmdContent := fmt.Sprintf(`@echo off
303-
set _BIN_DIR=%s\
304-
%%_BIN_DIR%%%s.exe --target=%s -fno-addrsig %%*"`, tcBin, toolName, tc.clangPrefix)
305-
if _, err = tool.Write([]byte(toolCmdContent)); err != nil {
306-
log.Fatal(err)
307-
}
308-
return toolCmd
309-
}
310-
311292
type ndkConfig map[string]ndkToolchain // map: GOOS->androidConfig.
312293

313294
func (nc ndkConfig) Toolchain(arch string) ndkToolchain {

0 commit comments

Comments
 (0)