Thread: [Fremantle Maemo5] Running Rust programs on N900
View Single Post
Posts: 88 | Thanked: 411 times | Joined on Mar 2010 @ southern Italy
#4
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
Step 2: enter the newly-created directory and edit the Cargo.toml file (conceptually a "makefile" for Rust), filling a dependencies section with default libc and x11-dl crates:
Code:
[dependencies]
libc = "*"
x11-dl = "*"
Step 3: edit some Hello World example (like this one, that only shows a white empty window) for desktop PC, making cargo download, compile and link the x11-dl package source:
Code:
cargo run
Step 4: we now need a small hack in the x11-dl source because the lib X11 6.2.0 on the N900 is quite old and does not support four functions present in lib X11 6.3.x and x11-dl.

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
< x11_link! { Xlib, x11, ["libX11.so.6", "libX11.so"], 767,
---
> x11_link! { Xlib, x11, ["libX11.so.6", "libX11.so"], 763,
241d240
<   pub fn XESetCopyEventCookie (_3: *mut Display, _2: c_int, _1: Option<unsafe extern "C" fn (*mut Display, *mut XGenericEventCookie, *mut XGenericEventCookie) -> c_int>) -> Option<unsafe extern "C" fn (*mut Display, *mut XGenericEventCookie, *mut XGenericEventCookie) -> c_int>,
254d252
<   pub fn XESetWireToEventCookie (_3: *mut Display, _2: c_int, _1: Option<unsafe extern "C" fn (*mut Display, *mut XGenericEventCookie, *mut xEvent) -> c_int>) -> Option<unsafe extern "C" fn (*mut Display, *mut XGenericEventCookie, *mut xEvent) -> c_int>,
278d275
<   pub fn XFreeEventData (_2: *mut Display, _1: *mut XGenericEventCookie) -> (),
298d294
<   pub fn XGetEventData (_2: *mut Display, _1: *mut XGenericEventCookie) -> c_int,
Step 5: verify that it still compiles and runs: check with ldd the executable, it won't show X11 libraries link prerequisites:
Code:
cargo clean
cargo run
ldd target/debug/x11n900
Step 6: cross-compile to ARM target and copy to N900 to some temporary executable directory:
Code:
cargo build --target=armv7-unknown-linux-gnueabihf --release
rsync -ave ssh target/armv7-unknown-linux-gnueabihf/release/x11n900 root@n900:/root/rust/
Step 7: in the N900 terminal, logged in as "user" (X11 programs shouldn't run as root; I'm using /root/rust as a temporary work directory as in the example of the other posts), execute:
Code:
LD_LIBRARY_PATH=/root/rust/ /root/rust/x11n900
Why does it work?
- 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.
 

The Following 3 Users Say Thank You to alfmar For This Useful Post: