Skip to content

Instantly share code, notes, and snippets.

@jmagnuson
Created August 12, 2021 04:39
Show Gist options
  • Save jmagnuson/f7297757f1c37529e32601d2c2b31338 to your computer and use it in GitHub Desktop.
Save jmagnuson/f7297757f1c37529e32601d2c2b31338 to your computer and use it in GitHub Desktop.
Steps to compile rust hello-world for mips32r1 (uclibc)
#!/bin/bash
if [ -z "$STAGING_DIR" ]; then
echo "STAGING_DIR not defined.. exiting"
exit 1
fi
#FOUND_PATH=`echo $PATH | grep -i uclibc`
if [ -z `echo $PATH | grep -i uclibc` ]; then
echo "mips32 compiler not in PATH.. exiting"
exit 1
fi
# 0. export variables
export CC_mips32_unknown_linux_uclibc=mips-openwrt-linux-uclibc-gcc
#export STAGING_DIR=
#export PATH=
rm -rf ~/.xargo/lib/rustlib/mips32-unknown-linux-uclibc
rm -rf hello
# 1. make project
cargo new --bin hello && cd hello
# 2. create toolchain params file
cat >mips32-unknown-linux-uclibc.json <<EOL
{
"arch": "mips",
"cpu": "mips32",
"data-layout": "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64",
"dynamic-linking": true,
"env": "uclibc",
"executables": true,
"features": "+mips32,+soft-float",
"has-elf-tls": true,
"has-rpath": true,
"is-builtin": true,
"linker-flavor": "gcc",
"linker-is-gnu": true,
"llvm-target": "mips-unknown-linux-uclibc",
"max-atomic-width": 32,
"os": "linux",
"position-independent-executables": true,
"pre-link-args": {
"gcc": [
"-Wl,--as-needed",
"-Wl,-z,noexecstack"
]
},
"relro-level": "full",
"target-c-int-width": "32",
"target-endian": "big",
"target-family": "unix",
"target-pointer-width": "32",
"vendor": "unknown"
}
EOL
# 3. create Xargo file
cat >Xargo.toml <<EOL
[target.mips32-unknown-linux-uclibc.dependencies.std]
features = []
EOL
# 4. create cargo cc config
mkdir -p .cargo/
cat >.cargo/config <<EOL
[build]
target = "mips32-unknown-linux-uclibc"
[target.mips32-unknown-linux-uclibc]
linker = "mips-openwrt-linux-uclibc-gcc"
ar = "mips-openwrt-linux-uclibc-ar"
EOL
# 5. patch Cargo.toml for panics
cat <<EOT >> Cargo.toml
[profile.dev]
panic = "abort"
[profile.release]
panic = "abort"
EOT
xargo build --target mips32-unknown-linux-uclibc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment