![]() |
Running Rust programs on N900
1 Attachment(s)
I happen to love Rust programming language (already running my code on ARM targets like Jolla phone and Beagleboard).
I just found a way to cross-compile Rust programs to run on a N900. Scenario: - write/debug some Rust program on my Ubuntu PC - cross-compile it for ARMv7 target (thanks, Rustup!) - copy executable file on the N900 and execute it there. On the N900: - have a directory with updated libc/ldso/libgcc_s... - use it: Code:
LD_LIBRARY_PATH=/root/rust ./myrustprogram - latest Rust releases require at least glibc 2.18 on the target N900 - (and glibc versions newer than 2.18 require kernel 2.6.32 or newer) - I didn't want to try risky upgrades. N900 preparation: - grab a glibc 2.18 binary (I found one from OpenSUSE 13.1/ARM) - grab the related libgcc_s binary (I found one from OpenSUSE 13.2/ARM) - unpack them on your desktop PC, for example: Code:
mkdir tmp Code:
ssh root@n900 mkdir /root/rust Code:
rsync -ave ssh lib/* /root/rust/ Code:
ssh root@n900 ln -s /root/rust/ld-linux-armhf.so.3 /lib Code:
cargo new mytest --bin Code:
LD_LIBRARY_PATH=/root/rust /root/mytest Why did it work? - Rust-compiled executables only require a few essential libraries (generally libc, libm, libpthread, libdl) - Rust-compiled executables are happy with glibc 2.18 (this is why the same executable for N900 works on the Beagleboard and Jolla phones) - I was lucky: N900 stock software uses legacy ld-linux.so.3 loader name instead of ld-linux-armhf.so.3 Note: - a trick like this will work on any platform as long as it uses the legacy loader name and the kernel is not too old for the glibc "updated" version; - some "updated" features may require extra fiddling (nsswitch, rpc, bindresvport; check the etc directory of the glibc package if you need them). Mission: accomplished. |
Re: Running Rust programs on N900
Forgot to add:
- you need to install Rustup (which allows to install both Rust compiler and the extra platforms for cross-compiling) - adding ARM platform target: Code:
rustup target install armv7-unknown-linux-gnueabihf Code:
[target.armv7-unknown-linux-gnueabihf] Code:
sudo apt-get install gcc-arm-linux-gnueabihf To deploy executables to Jolla SailfishOS no extra steps are required. For N900 you need the glibc 2.18 thing (and LD_LIBRARY_PATH) as described above. |
Re: Running Rust programs on N900
|
Re: Running Rust programs on N900
As a rule of thumb, if you don't need to link at compile time any existing libraries, you're a go.
I was able to add X11 basic support to N900 Rust programs. There is an x11-dl Rust "crate" that dinamically loads X11 libraries. I successfully used it to create a Rust program using X11 graphics system, test it on my Ubuntu 16.04 desktop, then cross-compile targetting N900. X11 library is messy, but getting it to link is quite a big leap. Step 1: create a new Rust project for a binary executable, for example: Code:
cargo new x11n900 --bin Code:
[dependencies] Code:
cargo run Edit the file ~/.cargo/registry/src/github*/x11-dl-*/src/xlib.rs to: - change the x11_link! macro line (not 767 functions but 763); - then erase the four lines defining XESetCopyEventCookie, XESetWireToEventCookie, XFreeEventData, XGetEventData. Actual patch should appear like this: Code:
37c37 Code:
cargo clean Code:
cargo build --target=armv7-unknown-linux-gnueabihf --release Code:
LD_LIBRARY_PATH=/root/rust/ /root/rust/x11n900 - x11-dl loads the X11 libraries at run-time: no need to install N900 SDK Scratchbox stuff. - N900 window manager adjusts the window size/position. Any other ideas about writing graphics-enabled programs in Rust to run on the N900? - you will need to fiddle with Scratchbox and graphics libraries sources and new versions - N900 sports Gtk 2.0 and Qt 4.7, wxWidget 2.8 is available to install, but apparently no Rust bindings/gluecode exist for those old versions. Disclaimer: - I did it "because I can"; I can't recommend wasting time with that baroque libX11. |
Re: Running Rust programs on N900
1 Attachment(s)
Arrrgh, slow, obscene, and I even had to manage redraw events...
|
Re: Running Rust programs on N900
|
All times are GMT. The time now is 07:32. |
vBulletin® Version 3.8.8