Trying to compile Rust code for a RG300 console (retrofw buildroot, mipsel, uclibc...)

I started a conversation on Reddit:

but I believe a forum is a better medium for this, as I'm likely to have ongoing doubts about this...

So I'm trying to build stuff for a RG-300 handheld console. It runs Linux and, for instance, comes with a wolf3d port:

$ file wolf3d/wolf3d
wolf3d/wolf3d: ELF 32-bit LSB executable, MIPS, MIPS32 version 1 (SYSV), dynamically linked, interpreter /lib/ld-uClibc.so.0, not stripped

I've been able to cross-compile mipsel-gnu binaries, but they don't seem to work. I don't think I have a good way to troubleshoot that, so I'm trying to cross-compile mipsel-musl binaries... while that's not uclibc like what the system runs, I suppose that could work?

I'm trying to write games, so the example I'm trying to compile is a rust-sdl2 example (actually, the "demo" example). I'm trying out various stuff, but the most promising one so far is:

$ CMAKE_C_COMPILER=mipsel-linux-gnu-gcc cargo build --release --example demo --target mipsel-unknown-linux-musl --features bundled
   Compiling sdl2-sys v0.32.6 (/home/alex/git/rust-sdl2/sdl2-sys)
   Compiling sdl2 v0.32.2 (/home/alex/git/rust-sdl2)
error: linking with `/usr/bin/mipsel-linux-gnu-gcc` failed: exit code: 1
  |
  = note: "/usr/bin/mipsel-linux-gnu-gcc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-Wl,--eh-frame-hdr" "-L" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib" "/home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/examples/demo-cd3dc7739d2262b7.demo.efjj4cfb-cgu.0.rcgu.o" "/home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/examples/demo-cd3dc7739d2262b7.demo.efjj4cfb-cgu.1.rcgu.o" "/home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/examples/demo-cd3dc7739d2262b7.demo.efjj4cfb-cgu.10.rcgu.o" "/home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/examples/demo-cd3dc7739d2262b7.demo.efjj4cfb-cgu.11.rcgu.o" "/home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/examples/demo-cd3dc7739d2262b7.demo.efjj4cfb-cgu.12.rcgu.o" "/home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/examples/demo-cd3dc7739d2262b7.demo.efjj4cfb-cgu.13.rcgu.o" "/home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/examples/demo-cd3dc7739d2262b7.demo.efjj4cfb-cgu.14.rcgu.o" "/home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/examples/demo-cd3dc7739d2262b7.demo.efjj4cfb-cgu.15.rcgu.o" "/home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/examples/demo-cd3dc7739d2262b7.demo.efjj4cfb-cgu.2.rcgu.o" "/home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/examples/demo-cd3dc7739d2262b7.demo.efjj4cfb-cgu.3.rcgu.o" "/home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/examples/demo-cd3dc7739d2262b7.demo.efjj4cfb-cgu.4.rcgu.o" "/home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/examples/demo-cd3dc7739d2262b7.demo.efjj4cfb-cgu.5.rcgu.o" "/home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/examples/demo-cd3dc7739d2262b7.demo.efjj4cfb-cgu.6.rcgu.o" "/home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/examples/demo-cd3dc7739d2262b7.demo.efjj4cfb-cgu.7.rcgu.o" "/home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/examples/demo-cd3dc7739d2262b7.demo.efjj4cfb-cgu.8.rcgu.o" "/home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/examples/demo-cd3dc7739d2262b7.demo.efjj4cfb-cgu.9.rcgu.o" "-o" "/home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/examples/demo-cd3dc7739d2262b7" "/home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/examples/demo-cd3dc7739d2262b7.53ka2isznhz5ijg9.rcgu.o" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-Wl,-O1" "-nodefaultlibs" "-L" "/home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/deps" "-L" "/home/alex/git/rust-sdl2/target/release/deps" "-L" "/home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/build/sdl2-sys-e7b69d6b74505090/out/lib" "-L" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib" "-Wl,-Bstatic" "/home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/deps/libsdl2-24fc8a218d815f7a.rlib" "/home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/deps/libsdl2_sys-6322dfb6db2ec021.rlib" "/home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/deps/libbitflags-cf0b9a229f903dd1.rlib" "/home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/deps/liblazy_static-5ca797e4c59098f8.rlib" "/home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/deps/liblibc-6c67bcfab9b7336f.rlib" "-Wl,--start-group" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libstd-b6414ae168385702.rlib" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libpanic_unwind-efbc2c947951b8cc.rlib" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libhashbrown-b177382d9a04ffbe.rlib" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/librustc_std_workspace_alloc-ba7d2244d33447d5.rlib" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libbacktrace-39569dc87e4ea301.rlib" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libbacktrace_sys-cd9e255bd82ddb5c.rlib" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/librustc_demangle-f83165e777dccb8d.rlib" "/tmp/rustcuPwFMj/libunwind-10b085de263b1750.rlib" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libcfg_if-9a4a22edf44da957.rlib" "/tmp/rustcuPwFMj/liblibc-68fabc677efa98de.rlib" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/liballoc-026dc0061b48e8b6.rlib" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/librustc_std_workspace_core-7bf75bb619341145.rlib" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libcore-ef54709e300503ed.rlib" "-Wl,--end-group" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libcompiler_builtins-4ed27d8420cb4abc.rlib" "-Wl,-Bdynamic" "-lSDL2" "-lgcc_s" "-lc"
  = note: /usr/lib/gcc-cross/mipsel-linux-gnu/8/../../../../mipsel-linux-gnu/bin/ld: skipping incompatible /home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/build/sdl2-sys-e7b69d6b74505090/out/lib/libSDL2.so when searching for -lSDL2
          /usr/lib/gcc-cross/mipsel-linux-gnu/8/../../../../mipsel-linux-gnu/bin/ld: /home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libstd-b6414ae168385702.rlib(std-b6414ae168385702.std.2w1w7wxd-cgu.0.rcgu.o): undefined reference to symbol 'dlsym@@GLIBC_2.0'
          /usr/lib/gcc-cross/mipsel-linux-gnu/8/../../../../mipsel-linux-gnu/bin/ld: //lib/mipsel-linux-gnu/libdl.so.2: error adding symbols: DSO missing from command line
          collect2: error: ld returned 1 exit status
          

error: aborting due to previous error

error: could not compile `sdl2`.

To learn more, run the command again with --verbose.

I believe cmake (run through build.rs using the cmake crate) is ignoring the CMAKE_* env var and creating an x86-64 binary:

$ ls -l /home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/build/sdl2-sys-e7b69d6b74505090/out/lib/libSDL2.so
lrwxrwxrwx 1 alex alex 14 Jan  9 21:15 /home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/build/sdl2-sys-e7b69d6b74505090/out/lib/libSDL2.so -> libSDL2-2.0.so
alex@molly:~/git/rust-sdl2$ ls -l /home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/build/sdl2-sys-e7b69d6b74505090/out/lib/libSDL2-2.0.so
lrwxrwxrwx 1 alex alex 16 Jan  9 21:15 /home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/build/sdl2-sys-e7b69d6b74505090/out/lib/libSDL2-2.0.so -> libSDL2-2.0.so.0
alex@molly:~/git/rust-sdl2$ ls -l /home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/build/sdl2-sys-e7b69d6b74505090/out/lib/libSDL2-2.0.so.0
lrwxrwxrwx 1 alex alex 21 Jan  9 21:15 /home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/build/sdl2-sys-e7b69d6b74505090/out/lib/libSDL2-2.0.so.0 -> libSDL2-2.0.so.0.10.0
alex@molly:~/git/rust-sdl2$ file /home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/build/sdl2-sys-e7b69d6b74505090/out/lib/libSDL2-2.0.so.0.10.0
/home/alex/git/rust-sdl2/target/mipsel-unknown-linux-musl/release/build/sdl2-sys-e7b69d6b74505090/out/lib/libSDL2-2.0.so.0.10.0: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=ee49ab77f8244d1db6123568a0f77fdd142cf7a4, not stripped

Any suggestions? The console comes with a buildroot system, but using an old version which doesn't seem to have Rust support...

So I tried going back to buildroot again. Managed to set up a working buildroot for my device, and successfully modified an existing project written in C (using SDL1, I think) and deployed the modified version.

Now I built buildroot from master, which comes with support for building rustc/cargo:

$ cargo -Vv
cargo 0.26.0
release: 0.26.0
$ rustc -Vv
rustc 1.33.0 (2aa4c46cf 2019-02-28)
binary: rustc
commit-hash: 2aa4c46cfdd726e97360c2734835aa3515e8c858
commit-date: 2019-02-28
host: x86_64-unknown-linux-gnu
release: 1.33.0
LLVM version: 8.0

, which are not super recent, but workable, I guess. The problem is that buildroot apparently doesn't build std, so if I try:

~/git/rust-sdl2$ cargo build --example demo
   Compiling getrandom v0.1.14
   Compiling sdl2 v0.32.2 (file:///home/alex/git/rust-sdl2)
error[E0432]: unresolved import `std`
  --> /home/alex/.cargo/registry/src/github.com-1ecc6299db9ec823/getrandom-0.1.14/src/error_impls.rs:13:5
   |
13 | use std::io;
   |     ^^^ did you mean `self::std`?

error[E0432]: unresolved import `libc`
  --> /home/alex/.cargo/registry/src/github.com-1ecc6299db9ec823/getrandom-0.1.14/src/util_libc.rs:18:13
   |
18 |         use libc::__errno_location as errno_location;
   |             ^^^^ maybe a missing `extern crate libc;`?

, any pointers?

Is there any way you could use musl-libc instead of uclibc? Because, otherwise, you're going to need to make a new target for the compiler.

Rust libstd is pretty tightly bound to the ABI of the libc right now, for complicated reasons like "errno looks like a variable but it's actually thread-local storage" and "what exactly is that typedef".

Rust currently had two Linux targets: one for glibc, and one for musl-libc.

That's what I was trying to do before (first post), but I failed. However, I tried to do that without using buildroot.

I've backed a bit buildroot and it seems to be building now. If that fails, apparently buildroot supports glibc and musl too, so that might be worth trying...

Ah, yes, now I get what you're doing.

I looked at the cmake crate's source code, and it does override the CMAKE_C_COMPILER. It uses the cc library to find the compiler, instead of just letting cmake do it.

The environment variable to configure the cc crate's compiler is just CC=mipsel-linux-gnu-gcc, according up its README.

Ah, another thing to try! Thanks :slight_smile:

I think buildroot's a safer option for now (as I can build C projects with SDL, which is more than what I can do without buildroot right now), but if I hit a deadend there, I'll go back and try to do that- buildroot is more laborious.

See:

http://lists.busybox.net/pipermail/buildroot/2020-January/271809.html

for some issues I'm having with buildroot (cc: @elebihan)

Tried @notriddle's suggestion, but didn't go far. Tried to go to SDL 1.2, but again, libc binaries do not seem to work, and building on MUSL is problematic:

$ CC=mipsel-linux-gnu-gcc cargo build --release --target mipsel-unknown-linux-musl
...
   Compiling sdl-demo v0.3.5 (/home/alex/git/rust-sdl/src/sdl-demo)
error: linking with `mipsel-linux-gnu-gcc` failed: exit code: 1
  |
  = note: "mipsel-linux-gnu-gcc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-Wl,--eh-frame-hdr" "-L" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/sdl_demo-f55bf19366d03a2d.sdl_demo.379673b8-cgu.0.rcgu.o" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/sdl_demo-f55bf19366d03a2d.sdl_demo.379673b8-cgu.1.rcgu.o" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/sdl_demo-f55bf19366d03a2d.sdl_demo.379673b8-cgu.10.rcgu.o" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/sdl_demo-f55bf19366d03a2d.sdl_demo.379673b8-cgu.2.rcgu.o" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/sdl_demo-f55bf19366d03a2d.sdl_demo.379673b8-cgu.3.rcgu.o" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/sdl_demo-f55bf19366d03a2d.sdl_demo.379673b8-cgu.4.rcgu.o" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/sdl_demo-f55bf19366d03a2d.sdl_demo.379673b8-cgu.5.rcgu.o" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/sdl_demo-f55bf19366d03a2d.sdl_demo.379673b8-cgu.6.rcgu.o" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/sdl_demo-f55bf19366d03a2d.sdl_demo.379673b8-cgu.7.rcgu.o" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/sdl_demo-f55bf19366d03a2d.sdl_demo.379673b8-cgu.8.rcgu.o" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/sdl_demo-f55bf19366d03a2d.sdl_demo.379673b8-cgu.9.rcgu.o" "-o" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/sdl_demo-f55bf19366d03a2d" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/sdl_demo-f55bf19366d03a2d.31k7m8xrreivxzrc.rcgu.o" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-Wl,-O1" "-nodefaultlibs" "-L" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps" "-L" "/home/alex/git/rust-sdl/src/sdl-demo/target/release/deps" "-L" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib" "-Wl,-Bstatic" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/libsdl-8063a8b284d1b4d3.rlib" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/libnum-cbfd187794706650.rlib" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/libnum_rational-bcdc5c44a48e52d6.rlib" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/libnum_bigint-099e4fe4aaf288f4.rlib" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/libnum_complex-9739b21091164cd4.rlib" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/librustc_serialize-da9cc6e30a80c111.rlib" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/libnum_iter-d5c1e846c2502edf.rlib" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/libnum_integer-fe93e931c1d7da2c.rlib" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/libnum_traits-1830627636222f5b.rlib" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/librand-7901db0b189caaac.rlib" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/librand-9c7c8ac87d626c0d.rlib" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/liblibc-6c67bcfab9b7336f.rlib" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/liblibc-c3c01f36245aeb51.rlib" "-Wl,--start-group" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libstd-b6414ae168385702.rlib" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libpanic_unwind-efbc2c947951b8cc.rlib" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libhashbrown-b177382d9a04ffbe.rlib" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/librustc_std_workspace_alloc-ba7d2244d33447d5.rlib" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libbacktrace-39569dc87e4ea301.rlib" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libbacktrace_sys-cd9e255bd82ddb5c.rlib" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/librustc_demangle-f83165e777dccb8d.rlib" "/tmp/rustcPUPJo4/libunwind-10b085de263b1750.rlib" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libcfg_if-9a4a22edf44da957.rlib" "/tmp/rustcPUPJo4/liblibc-68fabc677efa98de.rlib" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/liballoc-026dc0061b48e8b6.rlib" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/librustc_std_workspace_core-7bf75bb619341145.rlib" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libcore-ef54709e300503ed.rlib" "-Wl,--end-group" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libcompiler_builtins-4ed27d8420cb4abc.rlib" "-Wl,-Bdynamic" "-lSDL" "-lgcc_s" "-lc"
  = note: /usr/lib/gcc-cross/mipsel-linux-gnu/8/../../../../mipsel-linux-gnu/bin/ld: /home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libstd-b6414ae168385702.rlib(std-b6414ae168385702.std.2w1w7wxd-cgu.0.rcgu.o): undefined reference to symbol 'dlsym@@GLIBC_2.0'
          /usr/lib/gcc-cross/mipsel-linux-gnu/8/../../../../mipsel-linux-gnu/bin/ld: //lib/mipsel-linux-gnu/libdl.so.2: error adding symbols: DSO missing from command line
          collect2: error: ld returned 1 exit status

At least there's no line about "skipping incompatible library" this time.

Try adding #![link(name="dl", kind="dylib")] to your main.rs file.

Nope, fails again, I think identically:

  = note: "mipsel-linux-gnu-gcc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-Wl,--eh-frame-hdr" "-L" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/sdl_demo-f55bf19366d03a2d.sdl_demo.379673b8-cgu.0.rcgu.o" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/sdl_demo-f55bf19366d03a2d.sdl_demo.379673b8-cgu.1.rcgu.o" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/sdl_demo-f55bf19366d03a2d.sdl_demo.379673b8-cgu.10.rcgu.o" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/sdl_demo-f55bf19366d03a2d.sdl_demo.379673b8-cgu.2.rcgu.o" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/sdl_demo-f55bf19366d03a2d.sdl_demo.379673b8-cgu.3.rcgu.o" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/sdl_demo-f55bf19366d03a2d.sdl_demo.379673b8-cgu.4.rcgu.o" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/sdl_demo-f55bf19366d03a2d.sdl_demo.379673b8-cgu.5.rcgu.o" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/sdl_demo-f55bf19366d03a2d.sdl_demo.379673b8-cgu.6.rcgu.o" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/sdl_demo-f55bf19366d03a2d.sdl_demo.379673b8-cgu.7.rcgu.o" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/sdl_demo-f55bf19366d03a2d.sdl_demo.379673b8-cgu.8.rcgu.o" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/sdl_demo-f55bf19366d03a2d.sdl_demo.379673b8-cgu.9.rcgu.o" "-o" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/sdl_demo-f55bf19366d03a2d" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/sdl_demo-f55bf19366d03a2d.31k7m8xrreivxzrc.rcgu.o" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-Wl,-O1" "-nodefaultlibs" "-L" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps" "-L" "/home/alex/git/rust-sdl/src/sdl-demo/target/release/deps" "-L" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib" "-Wl,-Bstatic" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/libsdl-8063a8b284d1b4d3.rlib" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/libnum-cbfd187794706650.rlib" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/libnum_rational-bcdc5c44a48e52d6.rlib" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/libnum_bigint-099e4fe4aaf288f4.rlib" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/libnum_complex-9739b21091164cd4.rlib" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/librustc_serialize-da9cc6e30a80c111.rlib" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/libnum_iter-d5c1e846c2502edf.rlib" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/libnum_integer-fe93e931c1d7da2c.rlib" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/libnum_traits-1830627636222f5b.rlib" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/librand-7901db0b189caaac.rlib" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/librand-9c7c8ac87d626c0d.rlib" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/liblibc-6c67bcfab9b7336f.rlib" "/home/alex/git/rust-sdl/src/sdl-demo/target/mipsel-unknown-linux-musl/release/deps/liblibc-c3c01f36245aeb51.rlib" "-Wl,--start-group" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libstd-b6414ae168385702.rlib" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libpanic_unwind-efbc2c947951b8cc.rlib" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libhashbrown-b177382d9a04ffbe.rlib" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/librustc_std_workspace_alloc-ba7d2244d33447d5.rlib" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libbacktrace-39569dc87e4ea301.rlib" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libbacktrace_sys-cd9e255bd82ddb5c.rlib" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/librustc_demangle-f83165e777dccb8d.rlib" "/tmp/rustcTd2PkH/libunwind-10b085de263b1750.rlib" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libcfg_if-9a4a22edf44da957.rlib" "/tmp/rustcTd2PkH/liblibc-68fabc677efa98de.rlib" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/liballoc-026dc0061b48e8b6.rlib" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/librustc_std_workspace_core-7bf75bb619341145.rlib" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libcore-ef54709e300503ed.rlib" "-Wl,--end-group" "/home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libcompiler_builtins-4ed27d8420cb4abc.rlib" "-Wl,-Bdynamic" "-lSDL" "-lgcc_s" "-lc"
  = note: /usr/lib/gcc-cross/mipsel-linux-gnu/8/../../../../mipsel-linux-gnu/bin/ld: /home/alex/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libstd-b6414ae168385702.rlib(std-b6414ae168385702.std.2w1w7wxd-cgu.0.rcgu.o): undefined reference to symbol 'dlsym@@GLIBC_2.0'
          /usr/lib/gcc-cross/mipsel-linux-gnu/8/../../../../mipsel-linux-gnu/bin/ld: //lib/mipsel-linux-gnu/libdl.so.2: error adding symbols: DSO missing from command line
          collect2: error: ld returned 1 exit status

Well, adding some stuff to the source's .cargo/config allowed me to compile:

$ cat ../../.cargo/config
[build]
rustflags = ["-C", "link-args=-ldl -lutil -lpthread"]

The result is

target/mipsel-unknown-linux-musl/release/sdl-demo: ELF 32-bit LSB shared object, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld.so.1, for GNU/Linux 3.2.0, BuildID[sha1]=36239a5af12cc0039a0725446fc473b1dc16ff1c, with debug_info, not stripped

But the resulting binary does not seem to work :frowning:

musl must be linked statically, as there is no musl so on RG300 (it only has uclibc)

Hi! You're the guy on the RetroFW discord, right?

Yeah, I guessed "dynamically-linked" was trouble :slight_smile: I think building statically-linked SDL stuff will be easier with rust-sdl2, instead of rust-sdl1, as that seems to be more suited for statically linking. I had some progress with:

export CC=mipsel-linux-gnu-gcc ; export CFLAGS="-DSDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS=1 -I/usr/lib/mipsel-linux-gnu/glib-2.0/include/" ; cargo build --release --target mipsel-unknown-linux-musl --example demo --features static-link,bundled

on rust-sdl2, but still no dice. And even if that works, I'm not sure SDL2 + musl will work on the RG300 (buildroot seems to support SDL2, but I'm not sure there's anything working on my RG300 with SDL2... everything seems to be using SDL1).

Hi! You're the guy on the RetroFW discord, right?

Yeah that's me

I don't think anyone got SDL2 working on RetroFW yet. SDL1 static linking should work (just make sure you link the buildroot SDL, it comes with lots of patches https://github.com/retrofw/buildroot/tree/master/package/sdl)

DSDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS

There is also no X11 on RetroFW

Yay, moved forward a bit. I can now build a program that draws a fuzzy red rectangle and crashes :smiley:

I've put some notes about it at:

https://github.com/alexpdp7/retrofw2-rust

, in case someone wants to follow along. However, it does seem that you can do RetroFW game development on Rust!

The plot thickens. Most stuff I build crashes immediately. As I had my suspicions about rust-sdl being wonky, I tried playing with https://github.com/Roysten/rust-framebuffer .

Playing with that, I've been able to write a minimal program that crashes, which just does:

let x: i32 = unsafe { mem::zeroed() };
println!("{}", x);

, which according to zeroed in core::mem - Rust should be valid code, but that results in SIGILL (illegal instruction, apparently).

I can do prints and stuff to the console...

Anyone has any idea on how to proceed from there? (this is rustc 1.33.0 using mipsel-unknown-linux-uclibc , compiled using buildroot)

The next step could be looking at the assembly to see which instruction is illegal.
RG300 has an Ingenic XBurst CPU (jz4760b) that supports MIPS32r2 instructions with lots of extensions.

I tried RUSTFLAGS="--emit asm" cargo build... but it wasn't really obvious to me how to find out the instruction that causes the crash.

I was also doing debug builds. However, if I do a release build, mem::zeroed works (!).

I tried some other rust-framebuffer examples in release mode, and they continue failing, but in different places. Will poke at that a bit.

What I fear is that buildroot is building 1.33.0, which will soon be a year old, so even if I find the issue, I'll likely be told to update... so perhaps I should work on trying to get a more recent version of Rust working under buildroot...

GDB will pause on SIGILL by default. For seeing asm in GDB see Show current assembly instruction in GDB - Stack Overflow

Upgrading Rust in the buildroot may not be that difficult, here is an example of updating a package in RetroFW buildroot: https://github.com/retrofw/buildroot/pull/6

Nice. I'll poke around to see if I manage to run stuff using gdb (I suppose via telnet it will be possible).

I fear the patches that buildroot ships will no longer apply, but will give it a try...