tyfkda / xcc

Standalone C compiler/assembler/linker/libc for x86-64/aarch64/riscv64/wasm
https://tyfkda.github.io/xcc/
MIT License
197 stars 14 forks source link

consider making WASI optional #127

Closed ghost closed 12 months ago

ghost commented 12 months ago

I have been using wcc for a personal project (in different ways across time) for a while, but one change that has made it awkward for me to continue using wcc is the (somewhat recent) introduction of WASI as a target.

For my use case specifically, it would be wonderful if there were an option to use wcc to target freestanding Wasm. That is to say, WebAssembly without the library functions that would require WASI. Under this “freestanding mode”, things like malloc, strchr would continue to work, but other things like write, open, printf, fopen wouldn’t.

Note that the C specification does define specifically a “freestanding” option for implementations. They are mainly used in things like baremetal compilers (for things such as microcontrollers, where there is no underlying operating system and no concept of things like a file system), but I think it works well for Wasm without WASI too.

tyfkda commented 12 months ago

@zamfofex I'm not sure this work for you, but following command line option might help:

ghost commented 12 months ago

-nostdlib and -nostdinc don’t cover my intended use case, because they also prevent me from using e.g. malloc, strlen, etc. which don’t depend on WASI.

Ideally, I could be able to use something like wcc -ffreestanding ... to compile a program without needing WASI, but still being able to use functions that don’t need WASI.

Looking into it more carefully, what the specification calls “freestanding” is different from what I want, because it doesn’t require implementing those kinds of functions. :thinking:

I don’t know whether there is a good and obvious solution for what I want specifically, and I don’t think it’s bad to support WASI, so it’s fine if you want to close this issue.

tyfkda commented 12 months ago

@zamfofex For now, I can't think of a good way to separate WASI dependencies according to command line option. If you think of something, please let me know.