Skip to content
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

Closed
wants to merge 1 commit into from
Closed

Conversation

andrewrk
Copy link
Member

  • 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

 * 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;
Copy link
Contributor

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?

Copy link
Member Author

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 {
Copy link
Contributor

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
}

Copy link
Member Author

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);
Copy link
Contributor

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"
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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?

@andrewrk andrewrk closed this May 30, 2019
@andrewrk andrewrk deleted the wasm-libc branch May 30, 2019 00:33
@andrewrk
Copy link
Member Author

Landed in 01a4897

@erlend-sh
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants