github.com/tetratelabs/wazero@v1.2.1/internal/testing/dwarftestdata/data.go (about)

     1  package dwarftestdata
     2  
     3  import (
     4  	"bytes"
     5  	"embed"
     6  	_ "embed"
     7  	"fmt"
     8  	"os/exec"
     9  )
    10  
    11  // DWARF tests are build-sensitive in the sense that
    12  // whenever rebuilding the program, it is highly likely that
    13  // line number, source code file, etc, can change. Therefore,
    14  // even though these binaries are huge, we check them in to the repositories.
    15  
    16  //go:embed testdata/tinygo/main.wasm
    17  var TinyGoWasm []byte
    18  
    19  //go:embed testdata/zig/main.wasm
    20  var ZigWasm []byte
    21  
    22  // RustWasm comes with huge DWARF sections, so we do not check it in directly,
    23  // but instead xz-compressed one is.
    24  var RustWasm []byte
    25  
    26  //go:embed testdata/rust
    27  var testRustDir embed.FS
    28  
    29  func init() {
    30  	const wasmPath = "testdata/rust/main.wasm"
    31  	var err error
    32  	RustWasm, err = testRustDir.ReadFile(wasmPath)
    33  	if err != nil {
    34  		const xzPath = "testdata/rust/main.wasm.xz"
    35  		xzWasm, err := testRustDir.ReadFile(xzPath)
    36  		if err != nil {
    37  			panic(err)
    38  		}
    39  		cmd := exec.Command("xz", "-d")
    40  		cmd.Stdin = bytes.NewReader(xzWasm)
    41  		out := bytes.NewBuffer(nil)
    42  		cmd.Stdout = out
    43  		if err = cmd.Run(); err != nil {
    44  			fmt.Printf("Skipping DWARF tests for rusts as xz command failed: %v", err)
    45  			return
    46  		}
    47  		RustWasm = out.Bytes()
    48  	}
    49  }