With 3.4 rust support was announced, but I couldn’t find any documentation on how to get started with rust for sailfish. I understand that probably many things are not yet figured out or subject to change.
There is whisperfish, which uses rust and Actix. Asides from that there should be gecko/mozilla for which the rust support was introduced (haven’t found the place where this is build yet).
Gecko has a complex build process, so it’s probably not the best place to start with testing out rust. Something better might be the Cargo documentation first steps. I tried them out for my own interest and it worked as expected. The steps I used are below and maybe they’re useful for you too. You may need to alter some of these commands depending on your sfdk targets etc.
# Install tools into the sfdk
sfdk tools target package-install SailfishOS-3.4.0.22EA-armv7hl rust cargo
# Create example project
sfdk engine exec sb2 -t SailfishOS-3.4.0.22EA-armv7hl cargo new hello_world
cd hello_world
cat Cargo.toml
# Build the project
sfdk engine exec sb2 -t SailfishOS-3.4.0.22EA-armv7hl cargo build
# Copy executable binary to device
scp target/debug/hello_world nemo@192.168.1.8:~
# Run the executable on device
[nemo@Columba ~]$ ./hello_world
Hello, world!
Thanks a lot. This looks really good already. However I’m getting strange errors if I add a dependency (e.g. pest = “2.1.3”). It works totally fine on my machine, but not if I execute it with:
$ sfdk engine exec sb2 -t SailfishOS-3.4.0.22EA-armv7hl cargo build --verbose
Fresh ucd-trie v0.1.3
Compiling pest v2.1.3
Running `rustc --crate-name pest /home/mersdk/.cargo/registry/src/github.com-1ecc6299db9ec823/pest-2.1.3/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C debuginfo=2 -C metadata=ef32bfed2f3a56dc -C extra-filename=-ef32bfed2f3a56dc --out-dir /home/thilo/git/private/sailfish/rustinit/rust/hello_world/target/debug/deps -L dependency=/home/thilo/git/private/sailfish/rustinit/rust/hello_world/target/debug/deps --extern ucd_trie=/home/thilo/git/private/sailfish/rustinit/rust/hello_world/target/debug/deps/libucd_trie-a67709440dd0c9c5.rmeta --cap-lints allow`
error[E0463]: can't find crate for `ucd_trie`
--> /home/mersdk/.cargo/registry/src/github.com-1ecc6299db9ec823/pest-2.1.3/src/lib.rs:66:1
|
66 | extern crate ucd_trie;
| ^^^^^^^^^^^^^^^^^^^^^^ can't find crate
error: aborting due to previous error
For more information about this error, try `rustc --explain E0463`.
error: could not compile `pest`.
Caused by:
process didn't exit successfully: `rustc --crate-name pest /home/mersdk/.cargo/registry/src/github.com-1ecc6299db9ec823/pest-2.1.3/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C debuginfo=2 -C metadata=ef32bfed2f3a56dc -C extra-filename=-ef32bfed2f3a56dc --out-dir /home/thilo/git/private/sailfish/rustinit/rust/hello_world/target/debug/deps -L dependency=/home/thilo/git/private/sailfish/rustinit/rust/hello_world/target/debug/deps --extern ucd_trie=/home/thilo/git/private/sailfish/rustinit/rust/hello_world/target/debug/deps/libucd_trie-a67709440dd0c9c5.rmeta --cap-lints allow` (exit code: 1)
EDIT: it seems to be a problem with transitive dependencies. ucd-trie itsself is building fine.
Probably a filesystem issue?
If you really did do a complete reinstall then I’m not sure I’m afraid. On the off chance it survived the reinstall, you could try deleting the crate registry, like this:
Works now. I tried to reinstall sfdk and even made sure the machine is deleted from virtualbox, but it didnt help.
As mentioned I only tried VirtualBox before.
Now I installed the early access SDK with docker. One of both solved the problem. (docker seems likely. What were you using @flypig?)
I’m trying to create an example qt application with qmetaobject (patched to support qt5.6 by rubdos). I had to patch to set QT_SELECT to 5 instead of qt5. (You can use qmetaobject = { version = "0.1.4", git = "https://gitlab.com/thigg/qmetaobject-sfos-rs", branch = "sailfishos" })
It builds fine, but if I now try to run the example from the readme, I get the follwing:
Actually: No, not really. This isn’t only an illegal instruction, it’s no instruction at all, it doesn’t seem to be a TEXT segment. With gdb, what does bt tell us? How did it get there?
Getting an illegal insrtruction from a shared_null bytearray sounds a bit irrealistic. maybe some danglinig pointer somewhere?
also, where are you compiling this? Docker / SB2?
llvm can produce the stack trace; it might be interesting to have that too (BACKTRACE_FULL or something env var)
So I cant compare my phone to the emulator ( or run non-arm builds at all).
ARM
I tried to get more backtrace but failed (I have very little expertise here however, mainly just googling around). Tried RUST_BACKTRACE, but that didnt give anything.
The only further thing I found was putting a backtrace into gdb (or rust-gdb, doesnt seem to make a difference)
(gdb) bt full
#0 0xf6de4bd4 in QArrayData::shared_null () from /usr/lib/libQt5Core.so.5
No symbol table info available.
#1 0xf68a0ce4 in ?? () from /usr/lib/libQt5Qml.so.5
No symbol table info available.
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
FWIW, my fork was a hack to get around cross compiling Qt5.6. You might be interested in checking out this PR, which adds Qt5.6 detection to qmetaobject-rs https://github.com/woboq/qmetaobject-rs/pull/123
I’m trying to build it myself in sfdk now, to see whether it works, but I get
error: linker `arm-linux-gnueabihf-gcc` not found
|
= note: No such file or directory (os error 2)
… in the sb2 environment (sb2 -t SailfishOS-3.4.0.24-armv7hl cargo test --target-dir=sfdk-armv7hl/).
These new images contain 3.4.0.24, you might want to retry against that (former all-in image was 3.4.0.22 iirc).
Based on these images, I have built three others https://gitlab.com/rubdos/sailo-rs/, these contain the dependencies I need for Whisperfish (which is very few, on top of Rust, Cargo and Qt5-devel). These may interest you, although the build process is very different (cross compiling and -rpath-hacking, instead of emulated compiling). At least the source might interest you.