diff options
author | Patrick Scott <patrick@pmscott.com> | 2023-04-13 07:46:35 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-13 11:46:35 +0000 |
commit | 3125d8f0971bee56f069bbb33beb6686109fb71d (patch) | |
tree | 9f8de440f84995eb0c2b71d545ed7d976675c3f9 /go | |
parent | ba739e60421dddcf995a5cc260356c8228183d31 (diff) | |
download | bazelbuild-rules_go-3125d8f0971bee56f069bbb33beb6686109fb71d.tar.gz |
Add defines for assembly build (#3528)
* Add defines for assembly build
Fixes https://github.com/bazelbuild/rules_go/issues/1894 by adding GOOS_
GOARCH_ and GOOS_GOARCH_ defines for building assembly.
* Return a copy of args
* Use build.Default variables for os and arch
Add a compilation test that uses another architecture with conditional
inclusion of an assembly function. This mimics a real library that fails
to build under rules_go.
---------
Co-authored-by: Patrick Scott <patrick.scott@observeinc.com>
Diffstat (limited to 'go')
-rw-r--r-- | go/tools/builders/asm.go | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/go/tools/builders/asm.go b/go/tools/builders/asm.go index 133e950f..3d64c9ba 100644 --- a/go/tools/builders/asm.go +++ b/go/tools/builders/asm.go @@ -15,6 +15,7 @@ package main import ( + "go/build" "io/ioutil" "os" "path/filepath" @@ -24,6 +25,12 @@ import ( "strings" ) +var ASM_DEFINES = []string{ + "-D", "GOOS_" + build.Default.GOOS, + "-D", "GOARCH_" + build.Default.GOARCH, + "-D", "GOOS_GOARCH_" + build.Default.GOOS + "_" + build.Default.GOARCH, +} + // buildSymabisFile generates a file from assembly files that is consumed // by the compiler. This is only needed in go1.12+ when there is at least one // .s file. If the symabis file is not needed, no file will be generated, @@ -87,8 +94,7 @@ func buildSymabisFile(goenv *env, sFiles, hFiles []fileInfo, asmhdr string) (str seenHdrDirs[hdrDir] = true } } - // TODO(#1894): define GOOS_goos, GOARCH_goarch, both here and in the - // GoAsm action. + asmargs = append(asmargs, ASM_DEFINES...) asmargs = append(asmargs, "-gensymabis", "-o", symabisName, "--") for _, sFile := range sFiles { asmargs = append(asmargs, sFile.filename) @@ -107,6 +113,7 @@ func asmFile(goenv *env, srcPath, packagePath string, asmFlags []string, outPath if packagePath != "" && isGo119OrHigher() { args = append(args, "-p", packagePath) } + args = append(args, ASM_DEFINES...) args = append(args, "-trimpath", ".") args = append(args, "-o", outPath) args = append(args, "--", srcPath) |