@@ -1673,3 +1673,44 @@ func TestLinknameBSS(t *testing.T) {
16731673 t .Errorf ("executable failed to run: %v\n %s" , err , out )
16741674 }
16751675}
1676+
1677+ func TestWasmBuildinfo (t * testing.T ) {
1678+ testenv .MustHaveGoBuild (t )
1679+ t .Parallel ()
1680+
1681+ tmpdir := t .TempDir ()
1682+ src := filepath .Join (tmpdir , "hello.go" )
1683+
1684+ err := os .WriteFile (src , []byte (`package main; func main() { println("hello") }` ), 0666 )
1685+ if err != nil {
1686+ t .Fatal (err )
1687+ }
1688+
1689+ exe := filepath .Join (tmpdir , "hello.wasm" )
1690+ cmd := testenv .Command (t , testenv .GoToolPath (t ), "build" , "-o" , exe , src )
1691+
1692+ env := []string {"GOOS=js" , "GOARCH=wasm" }
1693+ for _ , v := range os .Environ () {
1694+ if strings .HasPrefix (v , "GOOS=" ) || strings .HasPrefix (v , "GOARCH=" ) {
1695+ continue
1696+ }
1697+ env = append (env , v )
1698+ }
1699+ cmd .Env = env
1700+
1701+ out , err := cmd .CombinedOutput ()
1702+ if err != nil {
1703+ t .Fatalf ("build failed: %v\n %s" , err , out )
1704+ }
1705+
1706+ const magic = "\xff Go buildinf:"
1707+
1708+ data , err := os .ReadFile (exe )
1709+ if err != nil {
1710+ t .Fatalf ("failed to read output file: %v" , err )
1711+ }
1712+
1713+ if ! bytes .Contains (data , []byte (magic )) {
1714+ t .Fatalf ("output does not contain buildinfo magic: %q" , out )
1715+ }
1716+ }
0 commit comments