Stream: general

Topic: Compile for the N3DS


view this post on Zulip Mode (Feb 26 2025 at 14:43):

Trying to compile an SDL cpp project for the N3DS, I am using SDL instructions here: https://github.com/libsdl-org/SDL/blob/main/docs/README-n3ds.md

I am adding wasmtime to my project through FetchContent, I have modified the first command to specify the target as so
cmake -S. -Bbuild -DCMAKE_TOOLCHAIN_FILE="$DEVKITPRO/cmake/3DS.cmake" -DCMAKE_BUILD_TYPE=Release -DWASMTIME_TARGET=armv6k-nintendo-3ds
with the following .cargo/config.toml

[target.armv6k-nintendo-3ds]
cc = "/opt/devkitpro/devkitARM/bin/arm-none-eabi-gcc"
cxx = "/opt/devkitpro/devkitARM/bin/arm-none-eabi-g++"
ar = "/opt/devkitpro/devkitARM/bin/arm-none-eabi-ar"
ranlib = "/opt/devkitpro/devkitARM/bin/arm-none-eabi-ranlib"
linker = "/opt/devkitpro/devkitARM/bin/arm-none-eabi-gcc"

The second build command however result in

[  0%] Performing build step for 'wasmtime-crate'
error: expected a table, but found a string for `target.armv6k-nintendo-3ds.cc` in /Users/themode/CLionProjects/NewAge/.cargo/config.toml
make[2]: *** [wasmtime/wasmtime-crate-prefix/src/wasmtime-crate-stamp/wasmtime-crate-build] Error 101
make[1]: *** [wasmtime/CMakeFiles/wasmtime-crate.dir/all] Error 2
make: *** [all] Error 2

Build processes always confuse me, I am wondering if all of this couldn't be handled by wasmtime itself?

Simple Directmedia Layer. Contribute to libsdl-org/SDL development by creating an account on GitHub.

view this post on Zulip Alex Crichton (Feb 26 2025 at 16:09):

I believe that you might accidentally be mixing up config.toml from the rust-lang/rust repository with Cargo's .cargo/config.toml. Those are similar but distinct formats for configuring various builds. Cargo for example, which you're configuring here with .cargo/config.toml does not understand cc, cxx, ar, or ranlib. I think you'll want to remove those keys from .cargo/config.toml to make some more progress in the build. To be clear though those keys are accepted and understood by rust-lang/rust's build which uses config.toml.

view this post on Zulip Mode (Feb 26 2025 at 16:15):

I initially didn't have them, but wasmtime then seemed to build for my current platform. How else should I define the 3ds target?

view this post on Zulip Alex Crichton (Feb 26 2025 at 16:24):

I'm pretty certain you'll need linker to tell cargo how to link, but otherwise the other keys are unrecognized by Cargo and are going to cause that error I think. When you tried and it built for the host was the linker configuration missing? If so I think it'll fix that

view this post on Zulip Alex Crichton (Feb 26 2025 at 16:24):

We have some brief docs on cross-compiling as well

view this post on Zulip Alex Crichton (Feb 26 2025 at 16:24):

(that doesn't cover the C API use case though)

view this post on Zulip Mode (Feb 26 2025 at 22:37):

Alright so I modified my config to

[unstable]
mtime-on-use = true
build-std = ["core", "alloc"]

[target.armv6k-nintendo-3ds]
ar = "/opt/devkitpro/devkitARM/bin/arm-none-eabi-ar"
linker = "/opt/devkitpro/devkitARM/bin/arm-none-eabi-gcc"

And my first build command to
cmake -S. -Bbuild -DCMAKE_TOOLCHAIN_FILE="$DEVKITPRO/cmake/3DS.cmake" -DCMAKE_BUILD_TYPE=Release -DWASMTIME_TARGET=armv6k-nintendo-3ds -DWASMTIME_USER_CARGO_BUILD_OPTIONS="-Zbuild-std"

And my problem now seems to be about rustix. Its very long so I won't send it all, but its essentially missing types like

error[E0425]: cannot find function `fstatfs` in module `c`
    --> /Users/themode/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustix-0.38.43/src/backend/libc/fs/syscalls.rs:1475:16
     |
1475 |         ret(c::fstatfs(borrowed_fd(fd), statfs.as_mut_ptr()))?;
     |                ^^^^^^^
     |
    ::: /Users/themode/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libc-0.2.161/src/unix/mod.rs:1384:5
     |
1384 |     pub fn fstatvfs(fd: ::c_int, buf: *mut statvfs) -> ::c_int;
     |     ----------------------------------------------------------- similarly named function `fstatvfs` defined here
     |

Rustix is apparently a syscall wrapper. I have personally no need at all for wasm WASI or any other way to run environment code through wasm. Is it necessary in other places?

view this post on Zulip Alex Crichton (Feb 26 2025 at 23:11):

You should be able to disable the "wasi" feature of the C API which will disable building that dependency. The error you're seeing is that the crate basically just doesn't compile for the target in question

view this post on Zulip Alex Crichton (Feb 26 2025 at 23:12):

You can also read some high-level information at https://docs.wasmtime.dev/stability-platform-support.html about platform support and no_std

view this post on Zulip Mode (Feb 27 2025 at 00:23):

I see the features here https://github.com/bytecodealliance/wasmtime/blob/main/crates/c-api/cmake/features.cmake
But I genuinely do not understand how to disable rustix.
SET(WASMTIME_DISABLE_ALL_FEATURES ON CACHE BOOL "")
Does reduce dependencies from 362 to 101, but rustix is still there with the same errors.

About no_std support, I don't believe this is necessary for the 3DS target?

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant - bytecodealliance/wasmtime

view this post on Zulip Mode (Feb 27 2025 at 00:42):

Is it perhaps something I should create a github issue for?

view this post on Zulip Alex Crichton (Feb 27 2025 at 01:56):

In theory yeah rustix gets dropped unless it's for wasi, but we also don't test no_std builds of the c-api just the main wasmtime crate. If you wouldn't mind filing an issue that'd be great!

view this post on Zulip Dan Gohman (Feb 27 2025 at 02:02):

rustix gets called if you enable the "runtime" feature, because it's used for mmap and such. However last time I looked at supporting armv6k-nintendo-3ds, the rust libc crate was lacking basic things like MAP_ANONYMOUS and PROT_READ and so on so I didn't get very far.

view this post on Zulip Mode (Feb 27 2025 at 02:17):

Well I have made this https://github.com/bytecodealliance/wasmtime/issues/10299

Not in a hurry at all (SDL seems to have issues as well), though I hope it will eventually be considered :)

Feature Support the Nintendo 3DS through the armv6k-nintendo-3ds target. Ensure c-api support as well. Benefit WebAssembly to the best game console ever conceived Implementation Compilation is curr...

view this post on Zulip Chris Fallin (Feb 27 2025 at 02:22):

Mode said:

Not in a hurry at all, though I hope it will eventually be considered :)

I don't have any particular ideas to help here, but just wanted to drop a friendly note to ensure expectations are properly aligned: the usual way that work gets done on Wasmtime, because folks are stretched so thin and we all have our own TODO-lists, is that if you want a particular niche thing, the best way to make it happen is to do it and then submit a PR :-) Apologies if you already had this sense, but "will be considered" implies maintainers are taking requests for work to do, which is usually not how open-source projects work

view this post on Zulip Chris Fallin (Feb 27 2025 at 02:23):

All that to say: if you do hack on this further, we'd be happy to review PRs!

view this post on Zulip Alex Crichton (Feb 27 2025 at 02:50):

Oh yes I'm definitely wrong, Dan's right that rustix is pulled in even without default features. That's me misremembering what we've got going on.

view this post on Zulip Dan Gohman (Feb 27 2025 at 06:03):

Does the N3DS have an mmap? I looked around for documentation, and all I could find was this, which doesn't seem to have mmap.


Last updated: Feb 28 2025 at 02:27 UTC