Skip to content

Instantly share code, notes, and snippets.

@Toasterson
Last active December 21, 2023 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Toasterson/90d19ecf4e0b69cfbcd9566a7c098eb8 to your computer and use it in GitHub Desktop.
Save Toasterson/90d19ecf4e0b69cfbcd9566a7c098eb8 to your computer and use it in GitHub Desktop.
Making a arm cross compile toolchain for illumos.
# This file allows any cargo project to cross compile.
# Adjust paths to the tools as needed.
# place unser .cargo/config inside the project.
[target.aarch64-unknown-illumos]
linker = "/var/lib/abuild/arm64-gate/build/cross/bin/aarch64-unknown-solaris2.11-gcc"
rustflags = [ "-Clink-arg=--sysroot=/var/lib/abuild/arm64-gate/build/sysroot" ]

This guide is part of the Tier 3 Target policy requirements and meant to show people how to install the rust compiler.

Note about stability

The illumos ARM ABI is not stable yet. Be sure to build your applications on the exact same version you want to run them on. If things break after update, please recompile.

Prerequisites:

  • illumos x86_64 installation
  • git

Install packages for the runtime

pfexec pkg install 

illumos Aarch64 Bootstrapping

in order to cross-compile from x86 to aarch64 we need to have a compatible toolchain installed on the host OS. Fortunately there is the arm64-gate repo that gets you started. I will not duplicate the information here as this will be changing at the moment, so follow along at https://github.com/richlowe/arm64-gate

Additionally to the packages needed, one should also install metapackages/build-essential on OpenIndiana to get all the other build parts. pkg install metapackages/build-essential

Build everything except the disk

cd arm64-gate
make download
make setup

Install the rust x86 toolchain

# sh is ksh on illumos thus we must pipe it to bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash

Download the rust source tree and build it

FORK=Toasterson
BRANCH=illumos-aarch64-target
git clone --branch $BRANCH https://github.com/$FORK/rust.git rust
cd rust
./configure --enable-extended --local-rust-root=$HOME/.rustup/toolchains/nightly-x86_64-unknown-illumos --default-linker=/usr/bin/gcc --build x86_64-unknown-illumos --host x86_64-unknown-illumos,aarch64-unknown-illumos --target aarch64-unknown-illumos,x86_64-unknown-illumos --prefix=/var/lib/abuild/.rust-toolchain --sysconfdir=etc --set=target.aarch64-unknown-illumos.linker=/var/lib/abuild/arm64-gate/build/cross/bin/aarch64-unknown-solaris2.11-gcc
CARGO_TARGET_AARCH64_UNKNOWN_ILLUMOS_RUSTFLAGS="-C link-arg=--sysroot=/var/lib/abuild/arm64-gate/build/sysroot" python x.py install
# Use different pre-set defaults than the global defaults.
#
# See `src/bootstrap/defaults` for more information.
# Note that this has no default value (x.py uses the defaults in `config.example.toml`).
profile = 'dist'
# Keeps track of major changes made to this configuration.
#
# This value also represents ID of the PR that caused major changes. Meaning,
# you can visit github.com/rust-lang/rust/pull/{change-id} to check for more details.
#
# A 'major change' includes any of the following
# - A new option
# - A change in the default values
#
# If `change-id` does not match the version that is currently running,
# `x.py` will prompt you to update it and check the related PR for more details.
change-id = 117813
[llvm]
[build]
# Build triple for the pre-compiled snapshot compiler. If `rustc` is set, this must match its host
# triple (see `rustc --version --verbose`; cross-compiling the rust build system itself is NOT
# supported). If `rustc` is unset, this must be a platform with pre-compiled host tools
# (https://doc.rust-lang.org/nightly/rustc/platform-support.html). The current platform must be
# able to run binaries of this build triple.
#
# If `rustc` is present in path, this defaults to the host it was compiled for.
# Otherwise, `x.py` will try to infer it from the output of `uname`.
# If `uname` is not found in PATH, we assume this is `x86_64-pc-windows-msvc`.
# This may be changed in the future.
build = 'x86_64-unknown-illumos'
# Which triples to produce a compiler toolchain for. Each of these triples will be bootstrapped from
# the build triple themselves. In other words, this is the list of triples for which to build a
# compiler that can RUN on that triple.
#
# Defaults to just the `build` triple.
host = ['x86_64-unknown-illumos', 'aarch64-unknown-illumos']
# Which triples to build libraries (core/alloc/std/test/proc_macro) for. Each of these triples will
# be bootstrapped from the build triple themselves. In other words, this is the list of triples for
# which to build a library that can CROSS-COMPILE to that triple.
#
# Defaults to `host`. If you set this explicitly, you likely want to add all
# host triples to this list as well in order for those host toolchains to be
# able to compile programs for their native target.
target = ['aarch64-unknown-illumos', 'x86_64-unknown-illumos']
# Instead of downloading the src/stage0.json version of Cargo specified, use
# this Cargo binary instead to build all Rust code
# If you set this, you likely want to set `rustc` as well.
cargo = '/var/lib/abuild/.rustup/toolchains/nightly-x86_64-unknown-illumos/bin/cargo'
# Instead of downloading the src/stage0.json version of the compiler
# specified, use this rustc binary instead as the stage0 snapshot compiler.
# If you set this, you likely want to set `cargo` as well.
rustc = '/var/lib/abuild/.rustup/toolchains/nightly-x86_64-unknown-illumos/bin/rustc'
# Enable a build of the extended Rust tool set which is not only the compiler
# but also tools such as Cargo. This will also produce "combined installers"
# which are used to install Rust and Cargo together.
# The `tools` (check `config.example.toml` to see its default value) option specifies
# which tools should be built if `extended = true`.
#
# This is disabled by default.
extended = true
# Arguments passed to the `./configure` script, used during distcheck. You
# probably won't fill this in but rather it's filled in by the `./configure`
# script. Useful for debugging.
configure-args = ['--enable-extended', '--local-rust-root=/var/lib/abuild/.rustup/toolchains/nightly-x86_64-unknown-illumos', '--default-linker=/usr/bin/gcc', '--build', 'x86_64-unknown-illumos', '--host', 'x86_64-unknown-illumos,aarch64-unknown-illumos', '--target', 'aarch64-unknown-illumos,x86_64-unknown-illumos', '--prefix=/var/lib/abuild/.rust-toolchain', '--sysconfdir=etc', '--set=target.aarch64-unknown-illumos.linker=/var/lib/abuild/arm64-gate/build/cross/bin/aarch64-unknown-solaris2.11-gcc']
[install]
# Where to install the generated toolchain. Must be an absolute path.
prefix = '/var/lib/abuild/.rust-toolchain'
# Where to install system configuration files.
# If this is a relative path, it will get installed in `prefix` above
sysconfdir = 'etc'
[rust]
# The default linker that will be hard-coded into the generated
# compiler for targets that don't specify a default linker explicitly
# in their target specifications. Note that this is not the linker
# used to link said compiler. It can also be set per-target (via the
# `[target.<triple>]` block), which may be useful in a cross-compilation
# setting.
#
# See https://doc.rust-lang.org/rustc/codegen-options/index.html#linker for more information.
default-linker = '/usr/bin/gcc'
[target.x86_64-unknown-illumos]
[target.aarch64-unknown-illumos]
# Linker to be used to bootstrap Rust code. Note that the
# default value is platform specific, and if not specified it may also depend on
# what platform is crossing to what platform.
# Setting this will override the `use-lld` option for Rust code when targeting MSVC.
linker = '/var/lib/abuild/arm64-gate/build/cross/bin/aarch64-unknown-solaris2.11-gcc'
[dist]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment