Hello everybody!
Rust 1.75 was merged to master March 15th 2024, so the next Sailfish SDK release should include it! Until then you can compile it yourself (or download it from my repository).
With this post you can build your own Rust 1.75.0 in the Platform SDK and install the packages in Sailfish SDK. You can then compile applications with it with a small workaround, as it you will see near end of this post. I’ll update this post if/when the repos change. Once the next SDK with updated Rust (and its dependencies) is out, I’ll post those instructions in a reply!
Note that all commands (except step 1) is done in the Sailfish Platform SDK prompt - not in tooling, not in any target. This goes for the package installation, too. This is a rare occurrence, but in this case it is necessary. This is because when the compilation reaches the part of python3 x.py build
which again executes a highly specific variant of cargo build
, it just stops/hangs with no activity whatsoever. If anyone has any ideas on how to fix that, please let us know!
Edit 1: Fix
zyper
typo, add link to rainemak’s blog post, fix wrong assumtions aboutproc-macro2
compilation error.
Edit 2: Bump to Rust 1.75, more typo fixes, use my own repository for LLVM 15, condense commands
Edit 3: Fixed and clarified LLVM version numbers
Edit 4: Removed theTMPDIR
workaround (“fixed” in the PR), fix a formatting error
Edit 5: Usesailfishos/rust
master instead of Rust 1.75 pull request by @rubdos
Step 1: Get Rust sources
Install git-lfs
and clone sailfishos/rust
:
$ git clone https://github.com/sailfishos/rust-cross.git
$ git clone https://github.com/sailfishos/rust.git
# Pro tip: Install git-lfs now to prevent downloading Rust 1.52 tarball
$ cd rust
$ git checkout 1.75.0+git1
Next, enter the Sailfish SDK:
$ sfossdk
Step 2: Install LLVM 16 and Clang 16 from my repository. The Sailfish repository is at version 14 at the time of writing, which is what Piggz’s OBS repositories currently offer. Rust 1.75 requires LLVM 15, however.
SDK $ sudo zypper ar --no-gpgcheck https://direc.kapsi.fi/sailfish-repo/i486 direc85
SDK $ sudo zypper ref
SDK $ sudo zypper in --force --from direc85 cmake llvm llvm-devel llvm-libs clang clang-devel clang-libs
Step 3: Install the cross compilation packages
Then a few more repos are needed in the Sailfish SDK prompt to install all the cross packages from. These instructions are adopted from @rainemak’s detailed post:
SDK $ sudo ssu ar jolla-aarch64 https://releases.jolla.com/releases/4.5.0.18/jolla/aarch64
SDK $ sudo ssu ar jolla-armv7hl https://releases.jolla.com/releases/4.5.0.18/jolla/armv7hl
SDK $ sudo zypper ref
SDK $ sudo zypper in cross-aarch64-gcc cross-aarch64-binutils cross-aarch64-as cross-aarch64-glibc cross-aarch64-glibc-devel cross-aarch64-glibc-headers cross-aarch64-kernel-headers
SDK $ sudo zypper in cross-armv7hl-gcc cross-armv7hl-binutils cross-armv7hl-as cross-armv7hl-glibc cross-armv7hl-glibc-devel cross-armv7hl-glibc-headers cross-armv7hl-kernel-headers
Step 4: Install rest of the build time dependencies
SDK $ sudo zypper in ccache cmake gdb libffi-devel make ncurses-devel "pkgconfig(libcurl)" "pkgconfig(liblzma)" "pkgconfig(openssl)" "pkgconfig(libz)" fakeroot
Step 5: Build Rust
This is pretty much just building a dumb package. Let’s build the actual compiler first - this takes 36 minutes on my laptop:
SDK $ cd ~/rust
SDK $ for ARCH in i486 armv7hl aarch64
do
rpmbuild --define "_topdir $PWD" --define "_sourcedir $PWD" --define "_target_cpu $ARCH" -bb rust.spec
done
Note that the i486
compiles “properly” and the aarch64
and armv7hl
architectures build stubs.
Step 6: Install the new Rust
SDK $ cd i486
SDK $ sudo zypper in *.rpm
Step 7: Create the Rust lib cross packages
SDK $ cd ~/rust-cross
SDK $ for ARCH in armv7hl aarch64
do
rpmbuild --define "_topdir $PWD" --define "_sourcedir $PWD" --define "_target_cpu $ARCH" -bb rust-cross-$ARCH.spec
done
Step 8: Make the packages available in Sailfish SDK
Note that I’m not adding my repository here, because it would also provide Rust 1.75 packages - which is not what we want in this case.
Exit the Sailfish SDK to your everyday shell. My project folder in SFDK is ~/SFOS
, so adjust accordingly. You also need to have a Sailfish application project, I’ll use Whisperfish here (as it’s a Rust application).
$ mkdir -p ~/SFOS/RPMS
$ cd ~/SFOS
$ git clone https://gitlab.com/whisperfish/whisperfish.git
$ cd whisperfish
$ sfdk config --global --push output-prefix ~/SFOS/RPMS
Next, move the packages you compiled to the “local repository”:
$ for ARCH in i486 armv7hl aarch64
do
mkdir -p ~/SFOS/RPMS/SailfishOS-4.5.0.18-$ARCH
mv ~/rust/RPMS/$ARCH/* ~/SFOS/RPMS/SailfishOS-4.5.0.18-$ARCH/
done
We’ll also need to download the necessary LLVM packages:
$ for ARCH in i486 armv7hl aarch64
do
URL=https://direc.kapsi.fi/sailfish-repo/$ARCH/rpm
for F in clang-libs-16.0.6+git1-0.$ARCH.rpm clang-16.0.6+git1-0.$ARCH.rpm clang-libs-16.0.6+git1-0.$ARCH.rpm
do
curl $URL/$F --output $F
done
done
Step 9: Install the Rust and LLVM packages to SFDK tooling
Since the tooling can’t access the host file system, you need to put the files to a web server somewhere (either on your LAN or on the Internet), upload the packages there, and download them back. I think this can be achieved on localhost too, but as I have a server available, I just used that. I use my own compilation results below, but you should use your own server here:
Download and install the necessary LLVM and Rust packages to the SFDK tooling:
$ sfdk exec SailfishOS-4.5.0.18 bash
# cd ~
# sfdk tools tooling exec SailfishOS-4.5.0.18 bash
# URL=https://direc.kapsi.fi/sailfish-repo/i486/rpm
# for F in rust-1.75.0+git1-1.i486.rpm cargo-1.75.0+git1-1.i486.rpm rust-std-static-aarch64-unknown-linux-gnu-1.75.0+git1-1.i486.rpm rust-std-static-armv7-unknown-linux-gnueabihf-1.75.0+git1-1.i486.rpm rust-std-static-i686-unknown-linux-gnu-1.75.0+git1-1.i486.rpm llvm-libs-16.0.6+git1-0.i486.rpm clang-libs-16.0.6+git1-0.i486.rpm clang-16.0.6+git1-0.i486.rpm
do
curl $URL/$F --output $F
done
# zypper in *.rpm
Step 10: Compile a package with the new Rust
Finally!
Go to the Sailfish application repo, set the target, and compile away!
Note: If you have compiled with another Rust version before, you must run
cargo clean
first!
$ cd ~/SFOS/whisperfish
$ for ARCH in i486 armv7hl aarch64
do
sfdk config --push target SailfishOS-4.5.0.18-$ARCH
sfdk build-shell cargo clean
sfdk build
done
As of February 19 2024, the .spec workaround is not needed any longer, because the issue with temporary files was worked around in the upcoming Rust 1.75 pull request instead. This means the .spec workaround still works, but is not needed nor recommended. This also means that the underlying issue in scratchbox2
is still there - see earlier versions of this post for the details.
Thanks to everyone involved in this rather massive Rust updating project: @rubdos, @mal, @rainemak, @vige and everyone else I forgot to mention here! This has been a huge undertaking and would not have happened without the help of many sailors and community members!