Skip to content

Commit 869baca

Browse files
aykevldeadprogram
authored andcommitted
wasi: specify wasi-libc in a different way
This way is more consistent with how picolibc is specified and allows generating a helpful error message. This error message should never be generated for TinyGo binary releases, only when doing local development.
1 parent 9c3e479 commit 869baca

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

builder/build.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil
186186
}
187187

188188
// Add libc dependency if needed.
189-
if config.Target.Libc == "picolibc" {
189+
root := goenv.Get("TINYGOROOT")
190+
switch config.Target.Libc {
191+
case "picolibc":
190192
path, job, err := Picolibc.load(config.Triple(), config.CPU(), dir)
191193
if err != nil {
192194
return err
@@ -198,12 +200,21 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil
198200
linkerDependencies = append(linkerDependencies, job)
199201
}
200202
ldflags = append(ldflags, path)
203+
case "wasi-libc":
204+
path := filepath.Join(root, "lib/wasi-libc/sysroot/lib/wasm32-wasi/libc.a")
205+
if _, err := os.Stat(path); os.IsNotExist(err) {
206+
return errors.New("could not find wasi-libc, perhaps you need to run `make wasi-libc`?")
207+
}
208+
ldflags = append(ldflags, path)
209+
case "":
210+
// no library specified, so nothing to do
211+
default:
212+
return fmt.Errorf("unknown libc: %s", config.Target.Libc)
201213
}
202214

203215
// Add jobs to compile extra files. These files are in C or assembly and
204216
// contain things like the interrupt vector table and low level operations
205217
// such as stack switching.
206-
root := goenv.Get("TINYGOROOT")
207218
for i, path := range config.ExtraFiles() {
208219
abspath := filepath.Join(root, path)
209220
outpath := filepath.Join(dir, "extra-"+strconv.Itoa(i)+"-"+filepath.Base(path)+".o")

targets/wasi.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"goarch": "arm",
66
"compiler": "clang",
77
"linker": "wasm-ld",
8+
"libc": "wasi-libc",
89
"cflags": [
910
"--target=wasm32--wasi",
1011
"--sysroot={root}/lib/wasi-libc/sysroot",
@@ -14,8 +15,7 @@
1415
"--allow-undefined",
1516
"--stack-first",
1617
"--export-dynamic",
17-
"--no-demangle",
18-
"{root}/lib/wasi-libc/sysroot/lib/wasm32-wasi/libc.a"
18+
"--no-demangle"
1919
],
2020
"emulator": ["wasmtime"],
2121
"wasm-abi": "generic"

targets/wasm.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"goarch": "wasm",
66
"compiler": "clang",
77
"linker": "wasm-ld",
8+
"libc": "wasi-libc",
89
"cflags": [
910
"--target=wasm32--wasi",
1011
"--sysroot={root}/lib/wasi-libc/sysroot",
@@ -14,8 +15,7 @@
1415
"--allow-undefined",
1516
"--stack-first",
1617
"--export-all",
17-
"--no-demangle",
18-
"{root}/lib/wasi-libc/sysroot/lib/wasm32-wasi/libc.a"
18+
"--no-demangle"
1919
],
2020
"emulator": ["node", "targets/wasm_exec.js"],
2121
"wasm-abi": "js"

0 commit comments

Comments
 (0)