Skip to content

Commit

Permalink
Add Rust Toolchain to build on aarch64 hosts
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Gilligan <sean@msgilligan.com>
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Reviewed-by: Sumit Garg <sumit.garg@linaro.org>
  • Loading branch information
msgilligan authored and jforissier committed May 24, 2024
1 parent f94a7e2 commit 4d33afe
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions toolchain.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
SHELL = /bin/bash
ROOT ?= $(CURDIR)/..
TOOLCHAIN_ROOT ?= $(ROOT)/toolchains
RUST_TOOLCHAIN_PATH ?= $(TOOLCHAIN_ROOT)/rust
UNAME_M := $(shell uname -m)
ARCH ?= arm

Expand Down Expand Up @@ -44,6 +45,16 @@ define build_toolchain
@touch $2/.done
endef

# Download the Rust toolchain
define dl-rust-toolchain
@if [ ! -d "$(1)" ]; then \
mkdir -p $(1) && \
export RUSTUP_HOME=$(1)/.rustup && \
export CARGO_HOME=$(1)/.cargo && \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path; \
fi
endef

ifeq ($(UNAME_M),x86_64)
ifeq ($(ARCH),arm)
AARCH32_PATH ?= $(TOOLCHAIN_ROOT)/aarch32
Expand All @@ -56,8 +67,6 @@ AARCH64_CROSS_COMPILE ?= $(AARCH64_PATH)/bin/aarch64-linux-gnu-
AARCH64_GCC_VERSION ?= arm-gnu-toolchain-11.3.rel1-x86_64-aarch64-none-linux-gnu
SRC_AARCH64_GCC ?= https://developer.arm.com/-/media/Files/downloads/gnu/11.3.rel1/binrel/$(AARCH64_GCC_VERSION).tar.xz

RUST_TOOLCHAIN_PATH ?= $(TOOLCHAIN_ROOT)/rust

.PHONY: toolchains
toolchains: aarch32-toolchain aarch64-toolchain rust-toolchain

Expand All @@ -69,16 +78,6 @@ aarch32-toolchain:
aarch64-toolchain:
$(call dltc,$(AARCH64_PATH),$(SRC_AARCH64_GCC),$(AARCH64_GCC_VERSION))

# Download the Rust toolchain
define dl-rust-toolchain
@if [ ! -d "$(1)" ]; then \
mkdir -p $(1) && \
export RUSTUP_HOME=$(1)/.rustup && \
export CARGO_HOME=$(1)/.cargo && \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path; \
fi
endef

.PHONY: rust-toolchain
rust-toolchain:
$(call dl-rust-toolchain,$(RUST_TOOLCHAIN_PATH))
Expand Down Expand Up @@ -131,7 +130,7 @@ AARCH64_PATH ?= $(TOOLCHAIN_ROOT)/aarch64
AARCH64_CROSS_COMPILE ?= $(AARCH64_PATH)/bin/aarch64-linux-

.PHONY: toolchains
toolchains: aarch32-toolchain $(AARCH64_PATH)/.done
toolchains: aarch32-toolchain $(AARCH64_PATH)/.done rust-toolchain

.PHONY: aarch32-toolchain
aarch32-toolchain:
Expand All @@ -140,6 +139,10 @@ aarch32-toolchain:
$(AARCH64_PATH)/.done:
$(call build_toolchain,aarch64,$(AARCH64_PATH),aarch64,gnu)

.PHONY: rust-toolchain
rust-toolchain:
$(call dl-rust-toolchain,$(RUST_TOOLCHAIN_PATH))

else # $(UNAME_M) != x86_64 or $(UNAME_M) != aarch64
AARCH32_PATH := $(TOOLCHAIN_ROOT)/aarch32
AARCH32_CROSS_COMPILE := $(AARCH32_PATH)/bin/arm-linux-
Expand Down

0 comments on commit 4d33afe

Please sign in to comment.