-
-
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
improve the libc of wasm32-freestanding target #2512
Conversation
* introduce wasm32-freestanding-musl .h files to fix conflicts with stddef.h and errno.h * fix an issue with zig build system regarding installation of webassembly libraries * add implementations to zig's libc: - strcmp - strncmp - strerror - strlen See #514
|
||
#ifndef __cplusplus | ||
#if defined(__NEED_wchar_t) && !defined(__DEFINED_wchar_t) | ||
typedef int wchar_t; |
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.
I think musl expects us to pass -fno-signed-wchar
to the compiler @richfelker could you confirm?
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.
Rich's profile says "I don't really use or prefer to use github." - I think we should respect that preference by asking questions in #musl
IRC channel
return std.mem.len(u8, s); | ||
} | ||
|
||
extern fn strncmp(_l: [*]const u8, _r: [*]const u8, _n: usize) c_int { |
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.
Could implement as:
return switch(std.mem.compare(u8, s1[0..n], s2[0..n])) {
.LessThan: -1,
.Equal: 0,
.GreaterThan: 1
}
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.
that will be an out of bounds index if n is bigger than strlen(s1) or strlen(s2)
} | ||
|
||
test "strncmp" { | ||
std.testing.expect(strncmp(c"a", c"b", 1) == -1); |
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.
use expectEqual
for better errors :)
@@ -6059,6 +6059,8 @@ set(ZIG_LIBC_FILES | |||
"include/x86_64-linux-musl/bits/stat.h" | |||
"include/x86_64-linux-musl/bits/syscall.h" | |||
"include/x86_64-linux-musl/bits/user.h" | |||
"include/wasm32-freestanding-musl/bits/alltypes.h" |
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.
Should we have created libc/musl/arch/wasm32/bits/alltypes.h.in
instead?
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.
I'm not sure why we even have those .in files; it might be a mistake.
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.
Want to make an issue to follow that up?
Landed in 01a4897 |
This was apparently blocking Lua for WebAssembly. WASM is picking up mainstream use as a scripting platform for games, and Lua is likely the most popular scripting language used in gamedev. If anyone is interested in picking up the ‘using zig to build lua for webassembly’ thread, a lot of game developers would pay close attention. |
conflicts with stddef.h and errno.h
webassembly libraries
See #514