Skip to content

Commit 8b923a1

Browse files
committed
Auto merge of #53190 - sekineh:thumb-cortex-m, r=jamesmunns
Add crate build test for `thumb*` targets. [IRR-2018-embedded] ## Summary This PR adds `run-make` test that compiles `cortex-m` crate for all supported `thumb*-none-*` targets using `cargo` and stage2 `rustc`. - Supported `thumb*-none-*` targets: - thumbv6m-none-eabi (Bare Cortex-M0, M0+, M1) - thumbv7em-none-eabi (Bare Cortex-M4, M7) - thumbv7em-none-eabihf (Bare Cortex-M4F, M7F, FPU, hardfloat) - thumbv7m-none-eabi (Bare Cortex-M3) ## How to run & Example output I tested locally and all targets succeeded like below: ``` ./x.py clean ./x.py test --target thumbv6m-none-eabi,thumbv7em-none-eabi,thumbv7em-none-eabihf,thumbv7m-none-eabi src/test/run-make ``` ``` Check compiletest suite=run-make mode=run-make (x86_64-unknown-linux-gnu -> thumbv6m-none-eabi) running 5 tests ..... test result: ok. 5 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ``` ## How to re-run Remove `stamp` file for the test run. ``` rm build/x86_64-unknown-linux-gnu/test/run-make/thumb-none-cortex-m/stamp ``` Then run `test` ``` ./x.py test --target thumbv6m-none-eabi,thumbv7em-none-eabi,thumbv7em-none-eabihf,thumbv7m-none-eabi src/test/run-make (snip) running 5 tests iiii. test result: ok. 1 passed; 0 failed; 4 ignored; 0 measured; 0 filtered out ``` ## Artifacts You can examine the artifacts under the directory below: ``` sekineh@sekineh-VirtualBox:~/rustme10$ ls -l build/x86_64-unknown-linux-gnu/test/run-make/thumb-none-cortex-m/thumb-none-cortex-m/ total 4 drwxrwxr-x 7 sekineh sekineh 4096 8月 14 22:40 cortex-m ``` where `build/x86_64-unknown-linux-gnu/test/run-make/thumb-none-cortex-m/thumb-none-cortex-m/` is came from TMPDIR variable. ## Other notes For `test.rs` modification, I used the same logic as: - https://github.com/rust-lang/rust/blame/d8b3c830fbcdd14d085209a8dcc3399151f3286a/src/bootstrap/dist.rs#L652-L657 ``` if builder.no_std(target) == Some(true) { // the `test` doesn't compile for no-std targets builder.ensure(compile::Std { compiler, target }); } else { builder.ensure(compile::Test { compiler, target }); } ``` It is a useful snippet when adding `no_std` support to `src/bootstrap` code. CC @kennytm @jamesmunns @nerdyvaishali
2 parents d06fa3a + ad78c2f commit 8b923a1

File tree

3 files changed

+82
-1
lines changed

3 files changed

+82
-1
lines changed

src/bootstrap/test.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -975,9 +975,19 @@ impl Step for Compiletest {
975975
builder.ensure(compile::Rustc { compiler, target });
976976
}
977977

978-
if builder.no_std(target) != Some(true) {
978+
if builder.no_std(target) == Some(true) {
979+
// the `test` doesn't compile for no-std targets
980+
builder.ensure(compile::Std { compiler, target });
981+
} else {
979982
builder.ensure(compile::Test { compiler, target });
980983
}
984+
985+
if builder.no_std(target) == Some(true) {
986+
// for no_std run-make (e.g. thumb*),
987+
// we need a host compiler which is called by cargo.
988+
builder.ensure(compile::Std { compiler, target: compiler.host });
989+
}
990+
981991
builder.ensure(native::TestHelpers { target });
982992
builder.ensure(RemoteCopyLibs { compiler, target });
983993

src/test/run-make/git_clone_sha1.sh

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash -x
2+
3+
# Copyright 2018 The Rust Project Developers. See the COPYRIGHT
4+
# file at the top-level directory of this distribution and at
5+
# http://rust-lang.org/COPYRIGHT.
6+
#
7+
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
8+
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
9+
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
10+
# option. This file may not be copied, modified, or distributed
11+
# except according to those terms.
12+
13+
# Usage: $0 project_name url sha1
14+
# Get the crate with the specified sha1.
15+
#
16+
# all arguments are required.
17+
#
18+
# See below link for git usage:
19+
# https://stackoverflow.com/questions/3489173#14091182
20+
21+
# Mandatory arguments:
22+
PROJECT_NAME=$1
23+
URL=$2
24+
SHA1=$3
25+
26+
function err_exit() {
27+
echo "ERROR:" $*
28+
exit 1
29+
}
30+
31+
git clone $URL $PROJECT_NAME || err_exit
32+
cd $PROJECT_NAME || err_exit
33+
git reset --hard $SHA1 || err_exit
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
-include ../../run-make-fulldeps/tools.mk
2+
3+
# How to run this
4+
# $ ./x.py clean
5+
# $ ./x.py test --target thumbv6m-none-eabi,thumbv7m-none-eabi src/test/run-make
6+
7+
# Supported targets:
8+
# - thumbv6m-none-eabi (Bare Cortex-M0, M0+, M1)
9+
# - thumbv7em-none-eabi (Bare Cortex-M4, M7)
10+
# - thumbv7em-none-eabihf (Bare Cortex-M4F, M7F, FPU, hardfloat)
11+
# - thumbv7m-none-eabi (Bare Cortex-M3)
12+
13+
# See https://stackoverflow.com/questions/7656425/makefile-ifeq-logical-or
14+
ifneq (,$(filter $(TARGET),thumbv6m-none-eabi thumbv7em-none-eabi thumbv7em-none-eabihf thumbv7m-none-eabi))
15+
16+
# For cargo setting
17+
RUSTC := $(RUSTC_ORIGINAL)
18+
LD_LIBRARY_PATH := $(HOST_RPATH_DIR)
19+
# We need to be outside of 'src' dir in order to run cargo
20+
WORK_DIR := $(TMPDIR)
21+
22+
HERE := $(shell pwd)
23+
24+
CRATE := cortex-m
25+
CRATE_URL := https://github.com/rust-embedded/cortex-m
26+
CRATE_SHA1 := a448e9156e2cb1e556e5441fd65426952ef4b927 # 0.5.0
27+
28+
all:
29+
env
30+
mkdir -p $(WORK_DIR)
31+
-cd $(WORK_DIR) && rm -rf $(CRATE)
32+
cd $(WORK_DIR) && bash -x $(HERE)/../git_clone_sha1.sh $(CRATE) $(CRATE_URL) $(CRATE_SHA1)
33+
cd $(WORK_DIR) && cd $(CRATE) && $(CARGO) build --target $(TARGET) -v
34+
else
35+
36+
all:
37+
38+
endif

0 commit comments

Comments
 (0)