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

feat: Wasm Linux support wasm32-wali #4244

Merged
merged 1 commit into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 76 additions & 69 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn src_hotfix_dir() -> PathBuf {
fn do_cc() {
let target = env::var("TARGET").unwrap();
if cfg!(unix) {
let exclude = ["redox", "wasi"];
let exclude = ["redox", "wasi", "wali"];
if !exclude.iter().any(|x| target.contains(x)) {
let mut cmsg = cc::Build::new();

Expand All @@ -26,7 +26,7 @@ fn do_cc() {
cmsg.compile("cmsg");
}

if target.contains("linux")
if (target.contains("linux") && !target.contains("wasm32"))
|| target.contains("android")
|| target.contains("emscripten")
|| target.contains("fuchsia")
Expand All @@ -35,10 +35,10 @@ fn do_cc() {
cc::Build::new().file("src/makedev.c").compile("makedev");
}
}
if target.contains("android") || target.contains("linux") {
if target.contains("android") || (target.contains("linux") && !target.contains("wasm32")) {
cc::Build::new().file("src/errqueue.c").compile("errqueue");
}
if target.contains("linux")
if (target.contains("linux") && !target.contains("wasm32"))
|| target.contains("l4re")
|| target.contains("android")
|| target.contains("emscripten")
Expand Down Expand Up @@ -3437,6 +3437,7 @@ fn test_linux(target: &str) {
let x86_64_gnux32 = target.contains("gnux32") && x86_64;
let riscv64 = target.contains("riscv64");
let loongarch64 = target.contains("loongarch64");
let wasm32 = target.contains("wasm32");
let uclibc = target.contains("uclibc");

let mut cfg = ctest_cfg();
Expand Down Expand Up @@ -3562,68 +3563,73 @@ fn test_linux(target: &str) {
cfg:
[loongarch64 || riscv64]: "asm/hwcap.h",
"asm/mman.h",
[gnu]: "linux/aio_abi.h",
"linux/can.h",
"linux/can/raw.h",
"linux/can/j1939.h",
"linux/dccp.h",
"linux/errqueue.h",
"linux/falloc.h",
"linux/filter.h",
"linux/fs.h",
"linux/futex.h",
"linux/genetlink.h",
"linux/if.h",
"linux/if_addr.h",
"linux/if_alg.h",
"linux/if_ether.h",
"linux/if_packet.h",
"linux/if_tun.h",
"linux/if_xdp.h",
"linux/input.h",
"linux/ipv6.h",
"linux/kexec.h",
"linux/keyctl.h",
"linux/magic.h",
"linux/memfd.h",
"linux/membarrier.h",
"linux/mempolicy.h",
"linux/mman.h",
"linux/module.h",
"linux/mount.h",
"linux/net_tstamp.h",
"linux/netfilter/nfnetlink.h",
"linux/netfilter/nfnetlink_log.h",
"linux/netfilter/nfnetlink_queue.h",
"linux/netfilter/nf_tables.h",
"linux/netfilter_arp.h",
"linux/netfilter_bridge.h",
"linux/netfilter_ipv4.h",
"linux/netfilter_ipv6.h",
"linux/netfilter_ipv6/ip6_tables.h",
"linux/netlink.h",
"linux/openat2.h",
// FIXME(linux): some items require Linux >= 5.6:
"linux/ptp_clock.h",
"linux/ptrace.h",
"linux/quota.h",
"linux/random.h",
"linux/reboot.h",
"linux/rtnetlink.h",
"linux/sched.h",
"linux/sctp.h",
"linux/seccomp.h",
"linux/sock_diag.h",
"linux/sockios.h",
"linux/tls.h",
"linux/uinput.h",
"linux/vm_sockets.h",
"linux/wait.h",
"linux/wireless.h",
"sys/fanotify.h",
// <sys/auxv.h> is not present on uclibc
[!uclibc]: "sys/auxv.h",
[gnu || musl]: "linux/close_range.h",
}

if !wasm32 {
headers! { cfg:
[gnu]: "linux/aio_abi.h",
"linux/can.h",
"linux/can/raw.h",
"linux/can/j1939.h",
"linux/dccp.h",
"linux/errqueue.h",
"linux/falloc.h",
"linux/filter.h",
"linux/fs.h",
"linux/futex.h",
"linux/genetlink.h",
"linux/if.h",
"linux/if_addr.h",
"linux/if_alg.h",
"linux/if_ether.h",
"linux/if_packet.h",
"linux/if_tun.h",
"linux/if_xdp.h",
"linux/input.h",
"linux/ipv6.h",
"linux/kexec.h",
"linux/keyctl.h",
"linux/magic.h",
"linux/memfd.h",
"linux/membarrier.h",
"linux/mempolicy.h",
"linux/mman.h",
"linux/module.h",
"linux/mount.h",
"linux/net_tstamp.h",
"linux/netfilter/nfnetlink.h",
"linux/netfilter/nfnetlink_log.h",
"linux/netfilter/nfnetlink_queue.h",
"linux/netfilter/nf_tables.h",
"linux/netfilter_arp.h",
"linux/netfilter_bridge.h",
"linux/netfilter_ipv4.h",
"linux/netfilter_ipv6.h",
"linux/netfilter_ipv6/ip6_tables.h",
"linux/netlink.h",
"linux/openat2.h",
// FIXME(linux): some items require Linux >= 5.6:
"linux/ptp_clock.h",
"linux/ptrace.h",
"linux/quota.h",
"linux/random.h",
"linux/reboot.h",
"linux/rtnetlink.h",
"linux/sched.h",
"linux/sctp.h",
"linux/seccomp.h",
"linux/sock_diag.h",
"linux/sockios.h",
"linux/tls.h",
"linux/uinput.h",
"linux/vm_sockets.h",
"linux/wait.h",
"linux/wireless.h",
"sys/fanotify.h",
// <sys/auxv.h> is not present on uclibc
[!uclibc]: "sys/auxv.h",
[gnu || musl]: "linux/close_range.h",
}
}

// note: aio.h must be included before sys/mount.h
Expand Down Expand Up @@ -4556,6 +4562,7 @@ fn test_linux_like_apis(target: &str) {
let gnu = target.contains("gnu");
let musl = target.contains("musl") || target.contains("ohos");
let linux = target.contains("linux");
let wali = target.contains("linux") && target.contains("wasm32");
let emscripten = target.contains("emscripten");
let android = target.contains("android");
assert!(linux || android || emscripten);
Expand Down Expand Up @@ -4605,7 +4612,7 @@ fn test_linux_like_apis(target: &str) {
cfg.generate(src_hotfix_dir().join("lib.rs"), "linux_fcntl.rs");
}

if linux || android {
if (linux && !wali) || android {
// test termios
let mut cfg = ctest_cfg();
cfg.header("asm/termbits.h");
Expand Down Expand Up @@ -4657,7 +4664,7 @@ fn test_linux_like_apis(target: &str) {
cfg.generate(src_hotfix_dir().join("lib.rs"), "linux_ipv6.rs");
}

if linux || android {
if (linux && !wali) || android {
// Test Elf64_Phdr and Elf32_Phdr
// These types have a field called `p_type`, but including
// "resolve.h" defines a `p_type` macro that expands to `__p_type`
Expand All @@ -4679,7 +4686,7 @@ fn test_linux_like_apis(target: &str) {
cfg.generate(src_hotfix_dir().join("lib.rs"), "linux_elf.rs");
}

if linux || android {
if (linux && !wali) || android {
// Test `ARPHRD_CAN`.
let mut cfg = ctest_cfg();
cfg.header("linux/if_arp.h");
Expand Down
3 changes: 2 additions & 1 deletion src/unix/linux_like/linux/arch/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ cfg_if! {
target_arch = "riscv64",
target_arch = "aarch64",
target_arch = "s390x",
target_arch = "loongarch64"
target_arch = "loongarch64",
target_arch = "wasm32"
))] {
pub const FS_IOC_GETFLAGS: Ioctl = 0x80086601;
pub const FS_IOC_SETFLAGS: Ioctl = 0x40086602;
Expand Down
3 changes: 3 additions & 0 deletions src/unix/linux_like/linux/musl/b64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ cfg_if! {
} else if #[cfg(any(target_arch = "loongarch64"))] {
mod loongarch64;
pub use self::loongarch64::*;
} else if #[cfg(any(target_arch = "wasm32"))] {
mod wasm32;
pub use self::wasm32::*;
} else {
// Unknown target_arch
}
Expand Down
Loading