Skip to content

Instantly share code, notes, and snippets.

@nanpuyue
Last active February 21, 2019 14:12
Show Gist options
  • Save nanpuyue/7b314ad1da77d3798a23cbfed397fbf7 to your computer and use it in GitHub Desktop.
Save nanpuyue/7b314ad1da77d3798a23cbfed397fbf7 to your computer and use it in GitHub Desktop.
build rust toolchain for mips-unknown-linux-musl
#!/bin/bash
# file: build_mips-unknown-linux-musl.sh
# date: 2018-12-24
# license: GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt
# author: nanpuyue <[email protected]> https://blog.nanpuyue.com
export LC_ALL=C
export STAGING_DIR="/build/openwrt-sdk-18.06.1/staging_dir"
export TOOLCHAIN="toolchain-mips_24kc_gcc-7.3.0_musl"
export PATH="$STAGING_DIR/$TOOLCHAIN/bin/:$PATH"
export AR_mips_unknown_linux_musl="mips-openwrt-linux-musl-ar"
export CC_mips_unknown_linux_musl="mips-openwrt-linux-musl-gcc"
export CXX_mips_unknown_linux_musl="mips-openwrt-linux-musl-g++"
export CFLAGS_mips_unknown_linux_musl="-I$STAGING_DIR/$TOOLCHAIN/inculde \
-I$STAGING_DIR/target-mips_24kc_musl/usr/inculde \
-L$STAGING_DIR/$TOOLCHAIN/lib \
-L$STAGING_DIR/target-mips_24kc_musl/usr/lib"
export MIPS_UNKNOWN_LINUX_MUSL_OPENSSL_STATIC=1
export MIPS_UNKNOWN_LINUX_MUSL_OPENSSL_DIR="$STAGING_DIR/target-mips_24kc_musl/usr"
export PKG_CONFIG_ALLOW_CROSS=1
export > env
./configure --release-channel=stable \
--musl-root-mips="$STAGING_DIR/$TOOLCHAIN" \
--set target.mips-unknown-linux-musl.linker="$CC_mips_unknown_linux_musl" \
--set target.mips-unknown-linux-musl.ar="$AR_mips_unknown_linux_musl"
./x.py dist --host mips-unknown-linux-musl --target mips-unknown-linux-musl -i -j4
TARGET_CC="mips-openwrt-linux-musl-gcc" ./x.py dist cargo \
--host mips-unknown-linux-musl --target mips-unknown-linux-musl \
--keep-stage 0 --keep-stage 1 --stage 2 -i -j4
@nanpuyue
Copy link
Author

nanpuyue commented Dec 23, 2018

before building:

download and extract openwrt sdk

export OPENWRT_SDK="/build/openwrt-sdk-18.06.1"

update and install feeds

cd "$OPENWRT_SDK"
./scripts/feeds update base
./scripts/feeds update packages
./scripts/feeds install -a

build libcurl with openssl & http2

cd "$OPENWRT_SDK"
make menuconfig #change build config of libcurl
make package/feeds/base/curl/compile -j4

build libunwind and get libunwind.a

patch feeds/base/package/libs/libunwind/Makefile with:

--- a/package/libs/libunwind/Makefile
+++ b/package/libs/libunwind/Makefile
@@ -52,7 +52,7 @@ endef
 define Build/InstallDev
        $(INSTALL_DIR) $(1)/usr/include $(1)/usr/lib/pkgconfig
        $(CP) $(PKG_INSTALL_DIR)/usr/include/*.h $(1)/usr/include
-       $(CP) $(PKG_INSTALL_DIR)/usr/lib/libunwin*.so* $(1)/usr/lib
+       $(CP) $(PKG_INSTALL_DIR)/usr/lib/libunwin*.{a,so}* $(1)/usr/lib
        $(CP) $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/* $(1)/usr/lib/pkgconfig/
 endef
cd "$OPENWRT_SDK"
make package/feeds/base/libunwind/compile -j4

build xz

cd "$OPENWRT_SDK"
make package/feeds/packages/xz/compile -j4

do something else

cd "$OPENWRT_SDK/staging_dir"
ln -srvf target-mips_24kc_musl/root-*/lib/libgcc_s_pic.a "toolchain-mips_24kc_gcc-7.3.0_musl/lib/libgcc_s.a"
ln -srvf target-mips_24kc_musl/usr/lib/libunwind.a "toolchain-mips_24kc_gcc-7.3.0_musl/lib/"
cd "$OPENWRT_SDK/staging_dir/toolchain-mips_24kc_gcc-7.3.0_musl/lib/gcc/mips-openwrt-linux-musl/7.3.0"
cp -vb crtbeginS.o crtbeginT.o
cp -vb crtendS.o crtend.o

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment