Skip to content

Commit

Permalink
tests/legacy/build_constraints: Split Go asm test into own package (#…
Browse files Browse the repository at this point in the history
…3652)

The native "go build" tool compiles assembly in a Cgo package with
the C compiler, and compiles assembly in a pure Go package with the
Go assembler. The build_constraints test previously mixed Go
assembler files with Cgo files. This caused the native go test to
fail with:

package using cgo has Go assembly file asm_linux_amd64.s

Splitting this into two separate packages fixes this.

This problem was reported in:
#2006

This will fix failing tests in my attempt to fix that issue:
#3648
  • Loading branch information
evanj authored Aug 12, 2023
1 parent 65ccde4 commit 07ec991
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 21 deletions.
4 changes: 0 additions & 4 deletions tests/legacy/build_constraints/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ go_library(
# Check that tags are observed.
"tag_l.go",
"tag_unknown.go",
# Check that constraints apply to assembly files.
"asm_arm64.s",
"asm_linux_amd64.s",
"asm_unknown.s",
# Check that constraints apply to cgo files.
"cgo_linux.go",
"cgo_unknown.go",
Expand Down
17 changes: 0 additions & 17 deletions tests/legacy/build_constraints/build_constraints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,6 @@ func TestTag(t *testing.T) {
check(tag, t)
}

func asm() int

func TestAsm(t *testing.T) {
got := asm()
var want int
if runtime.GOOS == "linux" {
want = 12
} else if runtime.GOARCH == "arm64" {
want = 75
} else {
want = 34
}
if got != want {
t.Errorf("got %d; want %d", got, want)
}
}

func TestCgoGo(t *testing.T) {
check(cgoGo, t)
}
Expand Down
20 changes: 20 additions & 0 deletions tests/legacy/build_constraints_go_asm/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_test(
name = "go_default_test",
size = "small",
srcs = ["build_constraints_go_asm_test.go"],
embed = [":go_default_library"],
)

go_library(
name = "go_default_library",
srcs = [
# Check that constraints apply to assembly files.
"asm_arm64.s",
"asm_linux_amd64.s",
"asm_unknown.s",
],
cgo = False,
importpath = "github.com/bazelbuild/rules_go/tests/build_constraints_go_asm",
)
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package build_constraints_go_asm

import (
"runtime"
"testing"
)

func asm() int

func TestAsm(t *testing.T) {
got := asm()
var want int
if runtime.GOOS == "linux" {
want = 12
} else if runtime.GOARCH == "arm64" {
want = 75
} else {
want = 34
}
if got != want {
t.Errorf("got %d; want %d", got, want)
}
}

0 comments on commit 07ec991

Please sign in to comment.