-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
WASI libc/sysroot #2336
WASI libc/sysroot #2336
Conversation
@@ -721,7 +724,7 @@ void get_target_triple(Buf *triple, const ZigTarget *target) { | |||
ZigLLVMGetSubArchTypeName(target->sub_arch), | |||
ZigLLVMGetVendorTypeName(target->vendor), | |||
ZigLLVMGetOSTypeName(get_llvm_os_type(target->os)), | |||
ZigLLVMGetEnvironmentTypeName(target->abi)); | |||
target_abi_name(target->abi)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WASISysroot doesn't exist in LLVM so I had to shim it in here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at it closer, I defined the enum in ZigLLVM space. Maybe I should move this transform back into ZigLLVMGetEnvironmentTypeName?
@@ -463,6 +464,8 @@ ZigLLVM_EnvironmentType target_abi_enum(size_t index) { | |||
const char *target_abi_name(ZigLLVM_EnvironmentType abi) { | |||
if (abi == ZigLLVM_UnknownEnvironment) | |||
return "none"; | |||
if (abi == ZigLLVM_WASISysroot) | |||
return "sysroot"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what to do about naming. Sysroot is super generic, but putting wasi-sysroot everywhere is super clunky: e.g. wasm32-wasi-wasisysroot
Only the file system, stdout/stderr, and main() depend on syscalls and thus WASI-Sysroot works quite well on generic (browser) wasm even without WASI. How should we expose this functionality? |
I think we can get away with following how libc is handled for Linux: std checks for From Lin Clark's "Standardizing WASI: A system interface to run WebAssembly outside the web"
Also,
This has been brought up by @andrewrk before. There can be a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've got the right idea here, and it's definitely planned to support a WASI libc with out-of-the-box zig. But we can't ship .a files or .o files - that's not how we achieve cross compilation. I'm happy to help with this, but I'll probably have to re-do a lot of this work myself, to double check your work. Perhaps you can start with something smaller, such as adding the wasi-sysroot C ABI?
I think WASI is a great candidate for having a pure-zig implementation of libc, and I would like to go down that road before shipping more libc implementations. These implementations can share a lot of code with the Zig standard library when targeting WASI without linking libc.
Related: #2380 |
This is based on the preliminary spec that exists in WebAssembly/wasi-libc-old#11
WASI wants to be a real build target, and what better way than defining libc? Per README, this should be the reference ABI so any changes would be ABI compatible... assuming it gets merged in.
Outstanding stuff (reference https://gist.github.com/fengb/be916b5fede576d8066fcb20b684e3c0):
$main
: the compiler outputted a$main
with 3 parameters:(func $main (type 4) (param i32 i32 i32) (result i32)
--export-all
since it exposes all of libc for no good reason.process_headers.zig
— I couldn't get it to run properly, so I'm not sure if I broke anything by working around it.WASI Sysroot
, which feels super clunky as a build targetwasm32-wasi-wasisysroot