Skip to content

ci: ensure build works with GOARCH=wasm #1757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ jobs:
go build -v ./...
go test -c -o /dev/null ./... >/dev/null

- name: Cross build wasm
env:
GOOS: js
GOARCH: wasm
run: |
go build -v ./...
go test -c -o /dev/null ./... >/dev/null

build-docs:
name: Build Documentation
runs-on: ubuntu-22.04
Expand Down
31 changes: 17 additions & 14 deletions cmd/bpf2go/gen/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@ import (
var ErrInvalidTarget = errors.New("unsupported target")

var targetsByGoArch = map[GoArch]Target{
"386": {"bpfel", "x86"},
"amd64": {"bpfel", "x86"},
"arm": {"bpfel", "arm"},
"arm64": {"bpfel", "arm64"},
"loong64": {"bpfel", "loongarch"},
"mips": {"bpfeb", "mips"},
"mipsle": {"bpfel", ""},
"mips64": {"bpfeb", ""},
"mips64le": {"bpfel", ""},
"ppc64": {"bpfeb", "powerpc"},
"ppc64le": {"bpfel", "powerpc"},
"riscv64": {"bpfel", "riscv"},
"s390x": {"bpfeb", "s390"},
"386": {"bpfel", "x86", ""},
"amd64": {"bpfel", "x86", ""},
"arm": {"bpfel", "arm", ""},
"arm64": {"bpfel", "arm64", ""},
"loong64": {"bpfel", "loongarch", ""},
"mips": {"bpfeb", "mips", ""},
"mipsle": {"bpfel", "", ""},
"mips64": {"bpfeb", "", ""},
"mips64le": {"bpfel", "", ""},
"ppc64": {"bpfeb", "powerpc", ""},
"ppc64le": {"bpfel", "powerpc", ""},
"riscv64": {"bpfel", "riscv", ""},
"s390x": {"bpfeb", "s390", ""},
"wasm": {"bpfel", "", "js"},
}

type Target struct {
Expand All @@ -36,6 +37,8 @@ type Target struct {
// Linux arch string, used to define __TARGET_ARCH_xzy macros used by
// https://github.com/libbpf/libbpf/blob/master/src/bpf_tracing.h
linux string
// GOOS override for use during tests.
goos string
}

// TargetsByGoArch returns all supported targets.
Expand Down Expand Up @@ -118,7 +121,7 @@ func FindTarget(id string) (Target, GoArches, error) {
}
}
slices.Sort(goarches)
return Target{id, ""}, goarches, nil
return Target{id, "", ""}, goarches, nil

case "native":
id = runtime.GOARCH
Expand Down
20 changes: 12 additions & 8 deletions cmd/bpf2go/gen/target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,32 @@ func TestCollectTargets(t *testing.T) {
}{
{
"bpf",
Target{"bpf", ""},
Target{"bpf", "", ""},
nil,
},
{
"bpfel",
Target{"bpfel", ""},
Target{"bpfel", "", ""},
clangArches["bpfel"],
},
{
"bpfeb",
Target{"bpfeb", ""},
Target{"bpfeb", "", ""},
clangArches["bpfeb"],
},
{
"amd64",
Target{"bpfel", "x86"},
Target{"bpfel", "x86", ""},
linuxArchesLE["x86"],
},
{
"386",
Target{"bpfel", "x86"},
Target{"bpfel", "x86", ""},
linuxArchesLE["x86"],
},
{
"ppc64",
Target{"bpfeb", "powerpc"},
Target{"bpfeb", "powerpc", ""},
linuxArchesBE["powerpc"],
},
{
Expand Down Expand Up @@ -111,10 +111,14 @@ func TestCollectTargetsErrors(t *testing.T) {
func TestGoarches(t *testing.T) {
exe := goBin(t)

for GoArch := range targetsByGoArch {
for GoArch, tgt := range targetsByGoArch {
t.Run(string(GoArch), func(t *testing.T) {
goOS := "linux"
if tgt.goos != "" {
goOS = tgt.goos
}
goEnv := exec.Command(exe, "env")
goEnv.Env = []string{"GOROOT=/", "GOOS=linux", "GOARCH=" + string(GoArch)}
goEnv.Env = []string{"GOROOT=/", "GOOS=" + string(goOS), "GOARCH=" + string(GoArch)}
output, err := goEnv.CombinedOutput()
qt.Assert(t, qt.IsNil(err), qt.Commentf("go output is:\n%s", string(output)))
})
Expand Down
2 changes: 1 addition & 1 deletion cmd/bpf2go/test/test_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/examples/getting_started/counter_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/examples/variables/variables_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/cgroup_skb/bpf_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/fentry/bpf_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/kprobe/bpf_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/kprobe_percpu/bpf_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/kprobepin/bpf_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/ringbuffer/bpf_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/tcprtt/bpf_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/tcprtt_sockops/bpf_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/tcx/bpf_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/tracepoint_in_c/bpf_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/xdp/bpf_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/endian_le.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build 386 || amd64 || amd64p32 || arm || arm64 || loong64 || mipsle || mips64le || mips64p32le || ppc64le || riscv64
//go:build 386 || amd64 || amd64p32 || arm || arm64 || loong64 || mipsle || mips64le || mips64p32le || ppc64le || riscv64 || wasm

package internal

Expand Down
Loading