Rust-lang (rustc/cargo) for OpenWrt - testing needed

I'm working on creating a rustup package so that OpenWrt can utilize rustc/cargo built applications.

I've created the start of a Makefile and sent it as a Draft PR here.

Anyone interested in lending a hand to get it working and tested? Currently, I've only cross-targeted mips/mips64, and even then I've hard-set my own target for testing.

Any assistance would be gratefully welcome!

Currently, the host package stuff doesn't get run in a timely manner. I'm using this to build Suricata as my test bench.

if i run things manually, they ALMOST run..

grommish@norwits:~/openwrt$ make -j1 V=sc package/feeds/packages/rustup/host/{configure,install}
Collecting package info: done
make[2]: Entering directory '/home/grommish/openwrt/scripts/config'
make[2]: 'conf' is up to date.
make[2]: Leaving directory '/home/grommish/openwrt/scripts/config'
make[1]: Entering directory '/home/grommish/openwrt'
make[2]: Entering directory '/home/grommish/openwrt/feeds/packages/lang/rustup'
. /home/grommish/openwrt/include/shell.sh; gzip -dc /home/grommish/openwrt/dl/rustup-1.22.1-src.tar.gz | tar -C /home/grommish/openwrt/build_dir/hostpkg/rustup-1.22.1/.. -xf -
[ ! -d ./src/ ] || cp -fpR ./src/* /home/grommish/openwrt/build_dir/hostpkg/rustup-1.22.1
touch /home/grommish/openwrt/build_dir/hostpkg/rustup-1.22.1/.prepareda5917125a56383f7f887bd7eec0404c0_6664517399ebbbc92a37c5bb081b5c53
RUSTUP_HOME=/home/grommish/openwrt/build_dir/hostpkg/.rustup CARGO_HOME=/home/grommish/openwrt/build_dir/hostpkg/.cargo /home/grommish/openwrt/build_dir/hostpkg/rustup-1.22.1/rustup-init.sh -y -v --profile default --target mips64-unknown-linux-muslabi64
info: downloading installer
info: profile set to 'default'
info: default host triple is x86_64-unknown-linux-gnu
warning: Updating existing toolchain, profile choice will be ignored
verbose: updating existing install for 'stable-x86_64-unknown-linux-gnu'
verbose: toolchain directory: '/home/grommish/openwrt/build_dir/hostpkg/.rustup/toolchains/stable-x86_64-unknown-linux-gnu'
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
verbose: creating temp file: /home/grommish/openwrt/build_dir/hostpkg/.rustup/tmp/_xik10jey7v5pnks_file
verbose: downloading file from: 'https://static.rust-lang.org/dist/channel-rust-stable.toml.sha256'
verbose: downloading with reqwest
verbose: deleted temp file: /home/grommish/openwrt/build_dir/hostpkg/.rustup/tmp/_xik10jey7v5pnks_file
verbose: creating temp file: /home/grommish/openwrt/build_dir/hostpkg/.rustup/tmp/t36cje6p0179wyoy_file.toml
verbose: downloading file from: 'https://static.rust-lang.org/dist/channel-rust-stable.toml'
verbose: downloading with reqwest
verbose: checksum passed
verbose: creating temp file: /home/grommish/openwrt/build_dir/hostpkg/.rustup/tmp/66l4gvtxmip4jwfs_file
verbose: downloading file from: 'https://static.rust-lang.org/dist/channel-rust-stable.toml.asc'
verbose: downloading with reqwest
verbose: deleted temp file: /home/grommish/openwrt/build_dir/hostpkg/.rustup/tmp/66l4gvtxmip4jwfs_file
verbose: Good signature from on https://static.rust-lang.org/dist/channel-rust-stable.toml from:
verbose: from builtin Rust release key
verbose:   RSA/85AB96E6-FA1BE5FE - Rust Language (Tag and Release Signing Key) <rust-key@rust-lang.org>
verbose:   Fingerprint: 108F 6620 5EAE B0AA A8DD 5E1C 85AB 96E6 FA1B E5FE
verbose: deleted temp file: /home/grommish/openwrt/build_dir/hostpkg/.rustup/tmp/t36cje6p0179wyoy_file.toml
info: latest update on 2020-08-03, rust version 1.45.2 (d3fb005a3 2020-07-31)
info: component 'rust-std' for target 'mips64-unknown-linux-muslabi64' is up to date
verbose: toolchain is already up to date
info: default toolchain set to 'stable-x86_64-unknown-linux-gnu'

  stable-x86_64-unknown-linux-gnu unchanged - rustc 1.45.2 (d3fb005a3 2020-07-31)


Rust is installed now. Great!

To get started you need Cargo's bin directory 
(/home/grommish/openwrt/build_dir/hostpkg/.cargo/bin) in your PATH
environment variable. Next time you log in this will be done
automatically.

To configure your current shell run 
source /home/grommish/openwrt/build_dir/hostpkg/.cargo/env
touch /home/grommish/openwrt/build_dir/hostpkg/rustup-1.22.1/.configured
make[2]: Leaving directory '/home/grommish/openwrt/feeds/packages/lang/rustup'
time: package/feeds/packages/rustup/host-configure#0.51#0.32#1.56
make[1]: Leaving directory '/home/grommish/openwrt'
make[2]: Entering directory '/home/grommish/openwrt/scripts/config'
make[2]: 'conf' is up to date.
make[2]: Leaving directory '/home/grommish/openwrt/scripts/config'
make[1]: Entering directory '/home/grommish/openwrt'
make[1]: *** No rule to make target 'package/feeds/packages/rustup/host/install'.  Stop.
make[1]: Leaving directory '/home/grommish/openwrt'
make: *** [/home/grommish/openwrt/include/toplevel.mk:235: package/feeds/packages/rustup/host/install] Error 2

Obviously, there is a define Host/Install in the Makefile, but it tells me there isn't one. Host/Configure doesn't seem to be called during a full build, because when Suricata gets built, it fails to find rustc.

And, just for clarity: in this case, Host/Configure sets up rustup, which then is used in Host/Install to actually install the target toolchain (which will be the one you cross-compile your images for - mips64-unknown-linux-muslabi64 in my case)

1 Like

I'm very interested in this, but the amount of time I can contribute is highly variable. Still, I'm up for testing builds and dummy packages and things.

1 Like

I managed to get rustup working and is it now being picked apart by the people who know better :slight_smile:

It'll need to be tested for various target platforms once it is done, since each rustc triple is target dependent. Feel free to look, comment, suggest :+1:

1 Like

I'm actively re-working this. It was a concern that the rustup installer uses pre-compiled binaries. I'm trying to see what can be done about it.

Anyone want to test the PR? I'm ready to call it finished from what I can test..

and it can be tested with this:

If it doesn't work, let me know. The suricata5 package is strictly for testing rustc/cargo, so I didn't polish the package yet. I'm just trying to test rustc/cargo at this point.

1 Like

Sorry for the radio silence, I got utterly derailed from this part of my project. I was going to test it on a couple of simple (pure Rust) projects, is it still in a PR or has it been committed?

Still a PR.. And one I've not updated.. I started working with rustc/cargo for Suricata, but I've been running into bigger issues with Suricata (https://forum.suricata.io/t/suricata6-0-0-beta1-on-openwrt-illegal-instruction-error/572). Rust seems to be working fine, other than the fact I need to have it tested across other platforms.

I can just give you the two makefiles, if you are familar with how to create a need package feed (i have them stored in ./feeds/packages/lang/rustup.

rustup Makefile:

# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk

PKG_NAME:=rustup
PKG_VERSION:=1.22.1
PKG_RELEASE:=1
PKG_LICENSE:=Apache-2.0 MIT
PKG_LICENSE_FILES:=LICENSE-APACHE LICENSE-MIT

PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/rust-lang/rustup.git
PKG_SOURCE_DATE:=2020-07-08
PKG_SOURCE_VERSION:=995002f2b88e8eea1cdf4879fa9e7cdc402b4938
PKG_HASH:=f37a7b56b36e4acf24675d6d3794059c228b750f780654900d3f8a5cecd52695
PKG_HOST_ONLY:=1

include $(INCLUDE_DIR)/host-build.mk
include $(INCLUDE_DIR)/package.mk
include ./rustc-triple.mk

define Package/rustup
  	SECTION:=lang
  	CATEGORY:=Languages
  	TITLE:=Rust Programming Language Installer
  	URL:=https://www.rust-lang.org/
endef

define Package/rustup/description
  The rustup package installs the Rust Programming Language (rustc/cargo)
  for use with packages that require Rust to compile.

  For Rust Support, add the following to the package:
  ***************************************************
  PKG_BUILD_DEPENDS:=rustup/host
  include ../../lang/rustup/rustc-triple.mk

  CONFIGURE_VARS += \
  	CARGO_HOME=$(CARGO_HOME) \
  	RUSTUP_HOME=$(RUSTUP_HOME) \
  	ac_cv_path_CARGO="$(CARGO_HOME)/bin/cargo" \
  	ac_cv_path_RUSTC="$(CARGO_HOME)/bin/rustc"

endef

RUSTUP_INIT_ARGS:= \
  	--profile default \
	--default-toolchain stable \
  	--target $(RUSTC_TARGET_ARCH)

CONFIGURE_VARS += \
	CARGO_HOME=$(CARGO_HOME) \
	RUSTUP_HOME=$(RUSTUP_HOME) \
	ac_cv_path_CARGO="$(CARGO_HOME)/bin/cargo" \
	ac_cv_path_RUSTC="$(CARGO_HOME)/bin/rustc"

define Host/Configure
	CARGO_HOME=$(CARGO_HOME) \
	RUSTUP_HOME=$(RUSTUP_HOME) \
	ac_cv_path_CARGO="$(CARGO_HOME)/bin/cargo" \
	ac_cv_path_RUSTC="$(CARGO_HOME)/bin/rustc" \
	$(BUILD_DIR_HOST)/$(PKG_SOURCE_SUBDIR)/rustup-init.sh -y -v $(RUSTUP_INIT_ARGS)
endef

define Host/Compile
	true
endef

define Host/Install
	CARGO_HOME=$(BUILD_DIR_HOST)/.cargo \
	RUSTUP_HOME=$(BUILD_DIR_HOST)/.rustup \
	$(BUILD_DIR_HOST)/.cargo/bin/rustup toolchain install stable -t $(RUSTC_TARGET_ARCH)
	$(BUILD_DIR_HOST)/.cargo/bin/rustup default stable
endef

define Package/rustup/compile
endef

define Package/rustup/install
endef

$(eval $(call HostBuild))
$(eval $(call BuildPackage,rustup))

rustc-triple.mk

# To enable rustc/cargo support in your packages, add:
# include $(TOPDIR)/feeds/packages/lang/rustup/rustc-triple.mk
# below include $(TOPDIR)/rules.mk
#
# You will need to add --host=$(RUSTC_TARGET_ARCH) to your packages
# CONFIGURE_VARS to cross-compile for the target architecture

RUSTC_ARCH_TARGETS:= \
aarch64-unknown-linux-gnu aarch64-unknown-linux-musl \
\
arm-unknown-linux-gnueabi arm-unknown-linux-gnueabihf \
arm-unknown-linux-musleabi arm-unknown-linux-musleabihf \
\
armv4t-unknown-linux-gnueabi \
\
armv5te-unknown-linux-gnueabi armv5te-unknown-linux-musleabi \
\
armv7-unknown-linux-gnueabi armv7-unknown-linux-gnueabihf \
armv7-unknown-linux-musleabi \
\
hexagon-unknown-linux-musl \
\
i586-unknown-linux-gnu i586-unknown-linux-musl \
\
i686-unknown-linux-gnu i686-unknown-linux-musl \
\
mips-unknown-linux-gnu mips-unknown-linux-musl mips-unknown-linux-uclibc \
\
mips64-unknown-linux-gnuabi64 mips64-unknown-linux-muslabi64 \
\
mips64el-unknown-linux-gnuabi64 mips64el-unknown-linux-muslabi64 \
\
mipsel-unknown-linux-gnu mipsel-unknown-linux-musl \
mipsel-unknown-linux-uclibc \
\
mipsisa32r6-unknown-linux-gnu mipsisa32r6el-unknown-linux-gnu \
\
mipsisa64r6-unknown-linux-gnuabi64 mipsisa64r6el-unknown-linux-gnuabi64 \
\
powerpc-unknown-linux-gnu powerpc-unknown-linux-musl \
\
powerpc64-unknown-linux-gnu powerpc64-unknown-linux-musl \
\
powerpc64le-unknown-linux-gnu powerpc64le-unknown-linux-musl \
\
riscv64gc-unknown-linux-gnu \
\
s390x-unknown-linux-gnu \
\
sparc-unknown-linux-gnu \
\
sparc64-unknown-linux-gnu \
\
thumbv7neon-unknown-linux-gnueabihf thumbv7neon-unknown-linux-musleabihf \
\
x86_64-unknown-linux-gnu x86_64-unknown-linux-musl

ifeq ($(CONFIG_LIBC_USE_MUSL),y)
RUSTC_TARGET_ARCH:=$(strip $(foreach v,$(filter $(ARCH)-%, $(RUSTC_ARCH_TARGETS)), $(if $(findstring -musl,$v),$v)))
else ifeq ($(CONFIG_LIBC_USE_GLIBC),y)
RUSTC_TARGET_ARCH:=$(strip $(foreach v,$(filter $(ARCH)-%, $(RUSTC_ARCH_TARGETS)), $(if $(findstring -gnu,$v),$v)))
else
RUSTC_TARGET_ARCH:=$(strip $(foreach v,$(filter $(ARCH)-%, $(RUSTC_ARCH_TARGETS)), $(if $(findstring -uclibc,$v),$v)))
endif

# More than one triple-target remains.
ifneq ($(word 2, $(RUSTC_TARGET_ARCH)),)
$(error RUSTC ERROR: Unsupported or Unknown Target Triple: $(RUSTC_TARGET_ARCH))
endif

# These are environment variables that are used by other packages to
# define where rustc/cargo are kept.
CARGO_HOME=$(BUILD_DIR_HOST)/.cargo
RUSTUP_HOME=$(BUILD_DIR_HOST)/.rustup

The important bits for your other packages will be:
PKG_BUILD_DEPENDS:=rustup/host
include ../../lang/rustup/rustc-triple.mk

CONFIGURE_VARS += \
	CARGO_HOME=$(CARGO_HOME) \
	RUSTUP_HOME=$(RUSTUP_HOME) \
	ac_cv_path_CARGO="$(CARGO_HOME)/bin/cargo" \
	ac_cv_path_RUSTC="$(CARGO_HOME)/bin/rustc"

and
--host=$(RUSTC_TARGET_ARCH)

as a ./configure arg if you need to specify the cross-compile

If you want to take a crack at Suricata6:
Suricata6 Makefile:

#
# Copyright (C) 2006-2015 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk

PKG_NAME:=suricata
PKG_VERSION:=6.0.0-beta1

PKG_SOURCE_PROTO:=git
PKG_SOURCE_DATE:=2020-09-04
PKG_SOURCE_VERSION:=222b3861024fbe1d40e3c97cfa65b5ce3243ba3d
PKG_SOURCE_URL:=https://github.com/OISF/suricata.git
PKG_HASH:=skip

PKG_FIXUP:=autoreconf
PKG_FIXUP:=patch-libtool
#PKG_FIXUP:=gettext-version
PKG_INSTALL:=1

PKG_BUILD_DEPENDS:=rustup/host

include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/nls.mk
include ../../lang/rustup/rustc-triple.mk

define Package/suricata6
    SUBMENU:=Firewall
    SECTION:=net
    CATEGORY:=Network
    DEPENDS:=+libpcre +libpcap +libnet-1.2.x +libyaml +zlib +libmagic \
       +jansson +libnfnetlink +lua +liblz4 +libnss +libopenssl \
	  +python3 +python3-yaml +libyaml +libcap-ng +luajit +libmaxminddb \
	  $(ICONV_DEPENDS)
    TITLE:=OISF Suricata IDS
    URL:=https://www.openinfosecfoundation.org/
endef

CONFIGURE_VARS += \
	CARGO_HOME=$(CARGO_HOME) \
	RUSTUP_HOME=$(RUSTUP_HOME) \
	ac_cv_path_CARGO="$(CARGO_HOME)/bin/cargo" \
	ac_cv_path_RUSTC="$(CARGO_HOME)/bin/rustc"

CONFIGURE_ARGS = \
  	--prefix="/usr/" \
  	--sysconfdir="/etc" \
  	--enable-nfqueue \
  	--localstatedir="/var" \
  	--enable-nfqueue \
  	--enable-debug \
	--enable-lua \
	--enable-geoip \
	--disable-gccmarch-native \
	--with-suricata-update \
	--host=$(RUSTC_TARGET_ARCH)

define Build/Prepare
	$(call Build/Prepare/Default)
	cd $(PKG_BUILD_DIR) && \
	git clone https://github.com/OISF/libhtp
endef

define Build/Configure
	cd $(PKG_BUILD_DIR) && ./autogen.sh
	$(call Build/Configure/Default)
endef

define Package/suricata6/install
	$(INSTALL_DIR) $(1)/usr/bin
	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/suricata $(1)/usr/bin/suricata
	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/suricatactl $(1)/usr/bin/suricatactl
	$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/suricatasc $(1)/usr/bin/suricatasc

	$(INSTALL_DIR) $(1)/usr/lib
	$(CP) -r $(PKG_INSTALL_DIR)/usr/lib/* $(1)/usr/lib/

	$(INSTALL_DIR) $(1)/usr/include
	$(CP) -r $(PKG_INSTALL_DIR)/usr/include/* $(1)/usr/include/

	$(INSTALL_DIR) $(1)/usr/share
	$(CP) -r $(PKG_INSTALL_DIR)/usr/share/* $(1)/usr/share/

	$(INSTALL_DIR) $(1)/etc/suricata
	$(CP) $(PKG_BUILD_DIR)/suricata.yaml \
	$(PKG_BUILD_DIR)/etc/classification.config \
	$(PKG_BUILD_DIR)/threshold.config \
	$(PKG_BUILD_DIR)/etc/reference.config \
	$(1)/etc/suricata/

#	$(INSTALL_DIR) $(1)/etc/suricata/rules
#	$(CP) $(PKG_BUILD_DIR)/rules/*.rules $(1)/etc/suricata/rules/
#	$(INSTALL_DIR) $(1)/etc/init.d
#	$(INSTALL_BIN) ./files/suricata.init $(1)/etc/init.d/suricata
endef

$(eval $(call BuildPackage,suricata6))

Ah this is perfect, thanks! I already have a repo for private packages and backports, so I'll try it out in there and let you know.

So I've hit a problem where it seems to be picking the wrong libc. I am definitely using musl, make menuconfig shows Symbol: LIBC_USE_MUSL [=y] (I had to enable advanced config options, which I usually leave disabled, and will now set back to disabled, but everything else seems to pick musl). But when rustup builds...

make[3]: Entering directory '/home/jason/Code/openwrt/feeds/myfeed/lang/rustup'
CARGO_HOME=/home/jason/Code/openwrt/build_dir/hostpkg/.cargo RUSTUP_HOME=/home/jason/Code/openwrt/build_dir/hostpkg/.rustup /home/jason/Code/openwrt/build_dir/hostpkg/.cargo/bin/rustup toolchain install stable -t mipsel-unknown-linux-uclibc
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
info: latest update on 2020-08-27, rust version 1.46.0 (04488afe3 2020-08-24)
error: component 'rust-std' for target 'mipsel-unknown-linux-uclibc' is unavailable for download for channel stable

Is this related to the --host=$(RUSTC_TARGET_ARCH) argument you mention? I didn't quite understand where that goes for a pure Rust project.

Update: Okay, putting $(info CONFIG_LIBC_USE_MUSL is $(CONFIG_LIBC_USE_MUSL)) in rust-triple.mk reveals that CONFIG_LIBC_USE_MUSL is (ie. blank). So I'm not sure what's going on there.

Another update: if I do the opposite of what I said at the start of this reply, and leave the advanced config option to use musl enabled... it works. This seems odd to me, since all I'm doing is re-selecting the default.

The script, which is shady at best, for determining the correct rustc triple is saying your on

error: component 'rust-std' for target 'mipsel-unknown-linux-uclibc' is unavailable for download for channel stable

It's reporting that your build is a misel uclibc build target.. What is your build machine?

CONFIG_LIBC_USE_MUSL/GLIBC/UCLIBC are the config flags to show which LibC toolchain.

If your CONFIG_LIBC_USE_MUSL is returing blank, it's because you probably aren't using it (it's checking to see if CONFIG_LIBC_USE_MUSL=y)

Check your .config file for the CONFIG_LIBC_USE_

# CONFIG_LIBC_USE_MUSL is not set

Are you using an external toolchain, by chance? I haven't put a check in for them yet.

Can you tell me what program/package your testing with?

If you are sure you are using MUSL, and can confirm it in your .config, for testing purposes, you can hard-set the triple in the rustc-triple.mk for testing by adding:

RUSTC_TARGET_ARCH:=mipsel-unknown-linux-musl

at the bottom of the file.. This will over-ride the janky script for testing.

If your package/program you are trying to compile uses ./configure or CMAKE, add the --host=$(RUSTC_TARGET_ARCH) to tell ./configure it's a cross-compile (or -Dhost=$(RUSTC_TARGET_ARCH) to your CMake args

ifeq ($(CONFIG_LIBC_USE_MUSL),y)
RUSTC_TARGET_ARCH:=$(strip $(foreach v,$(filter $(ARCH)-%, $(RUSTC_ARCH_TARGETS)), $(if $(findstring -musl,$v),$v)))
else ifeq ($(CONFIG_LIBC_USE_GLIBC),y)
RUSTC_TARGET_ARCH:=$(strip $(foreach v,$(filter $(ARCH)-%, $(RUSTC_ARCH_TARGETS)), $(if $(findstring -gnu,$v),$v)))
else
RUSTC_TARGET_ARCH:=$(strip $(foreach v,$(filter $(ARCH)-%, $(RUSTC_ARCH_TARGETS)), $(if $(findstring -uclibc,$v),$v)))
endif

Rust is going to be a pain.

Rust refuses to acknowledge soft-float floating point arches. ALL of their rustup binaries are compiled -mhard-float, which causes a SIGILL when a FPU opcode pops up when it shouldn't.

Kernel-level Emulation doesn't seem to fix the issue. So, now I'm back to trying to decide the next steps.

Build machine itself is amd64 (Lenovo laptop) running Ubuntu 20.04.5.

The target is a mipsel_24kc device.

I notice that your rust-triple.mk defaults to uclibc if it doesn't detect any of the config variables. Maybe musl would be a better default, since it's the default for most architectures?

Check your .config file for the CONFIG_LIBC_USE_

In my .config I have:

CONFIG_USE_MUSL=y

and

CONFIG_LIBC="musl"
CONFIG_TARGET_SUFFIX="musl"

Are you using an external toolchain, by chance?

Nope.

Literally just the hello world program from the Rust book (when they get to the Cargo stuff)!

The configure arg stuff was a red herring, don't worry about that

I wonder if this is a 18.06 vs 19.07 difference re. the .config variable?

Rust refuses to acknowledge soft-float floating point arches. ALL of their rustup binaries are compiled -mhard-float, which causes a SIGILL when a FPU opcode pops up when it shouldn't.

It is really starting to look like the only way this will happen is writing a bootstrap Rust compiler in C, hey.

Or, hear me out here... IN PYTHON.

The build version difference could very well be an issue. I build from the main branch as my device won't have an official version until 20.x is released.

I'm actually working on getting rust to bootstrap in the background :slight_smile:

It seems I'm going to have to compromise. I will need to get a precompiled rustc binary to bootstrap a recompile for the host and then use that to compile for the target.

Completely do-able, or should be. and then I can define my own triple targets, which will need to be done for any soft-float targets - at least it's easy to do.

No pressure, but you would make a lot of people extremely happy. All of Debian would be interested in this too, I believe.

Keep me posted and I'll keep testing things for you!

FYI, in case it wasn't apparent from the previous post.. If your device has a Floating Point Unit (hard-float), rustup is fine.. If you need a soft-float FPU, it won't work (or rather, it'll compiles and then just fails on the device)

I'm trying to build from source, which, yes, does use a pre-compiled version of rust-std to create the version that is used, but can't be helped. I'm running into additional issues stemming from the mips64 that I'm target'ing. Rust seems to have no desire to really do much outside of x86_64. For example, not only do they use -mhard-float to compile, but they statically link the libs, which is a no-go for mips (or at least mips64). Frustratingly, people have submitted issues and PR's over the years for these issues and were ignored (or told to rely on kernel FPU emulation - which actually doesn't work, if it ever did - at least not for me under 5.4.x).

So.. I'm at the point I'm hacking everything just to try to get it to work, and then work backwards on getting it to fit nicely into the existing build environment. It's not playing nice..

After some messing around with make menuconfig it looks like CONFIG_LIBC is a much more reliable test, at least in 18.06. I haven't checked in 19+. For example, even without going into the advanced toolchain settings, by default I have:

CONFIG_LIBC="musl"

If I do change that to glibc in the advanced toolchain settings, then I get

CONFIG_LIBC="glibc"

So it looks like this one works even when the default is used.

Oh! I just realised there's also CONFIG_TARGET_SUFFIX which gives you the suffix you're using ie. it's gnu for glibc. So you could potentially replace that whole set of checks with:

RUSTC_TARGET_ARCH:= \
	$(strip $(foreach \
		v, \
		$(filter $(ARCH)-%, $(RUSTC_ARCH_TARGETS)), \
		$(if $(findstring -$(CONFIG_TARGET_SUFFIX:"%"=%),$v),$v) \
		) \
	)

The "%" is to strip the quotes off.

1 Like

That would be fantastic. I'm still struggling with rust-from-source and how it handles things. It looks like I'm going to have to create custom targets for some things, and I keep running into linker issues for others.. We will just keep going at it, i supposed :slight_smile:

I've tried my Makefile modification and it seems to work nicely.

Regarding the other stuff, once you have things in a state you're happy to publish, put it up somewhere and maybe ask for help on /r/rust. I've found them to be super helpful.