Skip to content

Commit b84d549

Browse files
bors[bot]japaric
andcommitted
Merge #95
95: [RFC] remove build dependency on arm-none-eabi-gcc (binary blob alternative) r=japaric a=japaric Before this commit we used gcc to assemble external assembly files into object files that we linked into our Rust program. This commit drops the dependency on gcc by shipping the already assembled object files with this crate source code. --- This is an alternative to RFC #91 that doesn't require a breaking change or adding a new Cargo feature and can be implemented right now. See #91 for the rationale of dropping the dependency on gcc. This approach can be applied to other Cortex-M crates like cortex-m-semihosting and cortex-m (would subsume RFC #107). This seems like an overall better approach to me, but before I go opening more PRs I want to hear your thoughts, @rust-embedded/cortex-m closes #91 Co-authored-by: Jorge Aparicio <jorge@japaric.io>
2 parents e790d9b + 1dfbc86 commit b84d549

13 files changed

+71
-46
lines changed

cortex-m-rt/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
**/*.rs.bk
22
Cargo.lock
3+
bin/*.after
4+
bin/*.before
5+
bin/*.o
36
target/

cortex-m-rt/.travis.yml

+1-16
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,25 @@ language: rust
33
matrix:
44
include:
55
- env: TARGET=x86_64-unknown-linux-gnu
6-
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
7-
8-
- env: TARGET=thumbv6m-none-eabi
96
rust: stable
107
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
118

12-
- env: TARGET=thumbv6m-none-eabi CC=clang
9+
- env: TARGET=thumbv6m-none-eabi
1310
rust: stable
1411
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
1512

1613
- env: TARGET=thumbv7m-none-eabi
1714
rust: stable
1815
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
1916

20-
- env: TARGET=thumbv7m-none-eabi CC=clang
21-
rust: stable
22-
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
23-
2417
- env: TARGET=thumbv7em-none-eabi
2518
rust: stable
2619
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
2720

28-
- env: TARGET=thumbv7em-none-eabi CC=clang
29-
rust: stable
30-
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
31-
3221
- env: TARGET=thumbv7em-none-eabihf
3322
rust: stable
3423
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
3524

36-
- env: TARGET=thumbv7em-none-eabihf CC=clang
37-
rust: stable
38-
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
39-
4025
- env: TARGET=thumbv6m-none-eabi
4126
rust: nightly
4227
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)

cortex-m-rt/Cargo.toml

-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ name = "cortex-m-rt"
1010
repository = "https://github.com/japaric/cortex-m-rt"
1111
version = "0.5.2"
1212

13-
[build-dependencies]
14-
cc = "1.0.10"
15-
1613
[dependencies]
1714
r0 = "0.2.1"
1815

cortex-m-rt/asm.s

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.section .text.HardFault
12
.global HardFault
23
.thumb_func
34
HardFault:

cortex-m-rt/assemble.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
set -euxo pipefail
4+
5+
# cflags taken from cc 1.0.22
6+
7+
crate=cortex-m-rt
8+
9+
arm-none-eabi-as -march=armv6s-m asm.s -o bin/$crate.o
10+
ar crs bin/thumbv6m-none-eabi.a bin/$crate.o
11+
12+
arm-none-eabi-as -march=armv7-m asm.s -o bin/$crate.o
13+
ar crs bin/thumbv7m-none-eabi.a bin/$crate.o
14+
15+
arm-none-eabi-as -march=armv7e-m asm.s -o bin/$crate.o
16+
ar crs bin/thumbv7em-none-eabi.a bin/$crate.o
17+
ar crs bin/thumbv7em-none-eabihf.a bin/$crate.o
18+
19+
rm bin/$crate.o

cortex-m-rt/bin/thumbv6m-none-eabi.a

886 Bytes
Binary file not shown.

cortex-m-rt/bin/thumbv7em-none-eabi.a

886 Bytes
Binary file not shown.
886 Bytes
Binary file not shown.

cortex-m-rt/bin/thumbv7m-none-eabi.a

886 Bytes
Binary file not shown.

cortex-m-rt/build.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
extern crate cc;
2-
31
use std::env;
4-
use std::fs::File;
2+
use std::fs::{self, File};
53
use std::io::Write;
64
use std::path::PathBuf;
75

86
fn main() {
97
let target = env::var("TARGET").unwrap();
8+
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
109

1110
has_fpu(&target);
1211
let is_armv6m = is_armv6m(&target);
1312

1413
if target.starts_with("thumbv") {
15-
cc::Build::new().file("asm.s").compile("asm");
14+
fs::copy(
15+
format!("bin/{}.a", target),
16+
out_dir.join("libcortex-m-rt.a"),
17+
).unwrap();
18+
println!("cargo:rustc-link-lib=static=cortex-m-rt");
1619
}
1720

1821
// Put the linker script somewhere the linker can find it

cortex-m-rt/check-blobs.sh

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
# Checks that the blobs are up to date with the committed assembly files
4+
5+
set -euxo pipefail
6+
7+
for lib in $(ls bin/*.a); do
8+
filename=$(basename $lib)
9+
arm-none-eabi-objdump -Cd $lib > bin/${filename%.a}.before
10+
done
11+
12+
./assemble.sh
13+
14+
for lib in $(ls bin/*.a); do
15+
filename=$(basename $lib)
16+
arm-none-eabi-objdump -Cd $lib > bin/${filename%.a}.after
17+
done
18+
19+
for cksum in $(ls bin/*.after); do
20+
diff -u $cksum ${cksum%.after}.before
21+
done

cortex-m-rt/ci/install.sh

+3-5
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ set -euxo pipefail
33
main() {
44
if [ $TARGET != x86_64-unknown-linux-gnu ]; then
55
rustup target add $TARGET
6+
fi
67

7-
if [ ${CC:-gcc} = gcc ]; then
8-
mkdir gcc
8+
mkdir gcc
99

10-
curl -L https://developer.arm.com/-/media/Files/downloads/gnu-rm/7-2018q2/gcc-arm-none-eabi-7-2018-q2-update-linux.tar.bz2?revision=bc2c96c0-14b5-4bb4-9f18-bceb4050fee7?product=GNU%20Arm%20Embedded%20Toolchain,64-bit,,Linux,7-2018-q2-update | tar --strip-components=1 -C gcc -xj
11-
fi
12-
fi
10+
curl -L https://developer.arm.com/-/media/Files/downloads/gnu-rm/7-2018q2/gcc-arm-none-eabi-7-2018-q2-update-linux.tar.bz2?revision=bc2c96c0-14b5-4bb4-9f18-bceb4050fee7?product=GNU%20Arm%20Embedded%20Toolchain,64-bit,,Linux,7-2018-q2-update | tar --strip-components=1 -C gcc -xj
1311
}
1412

1513
main

cortex-m-rt/ci/script.sh

+16-18
Original file line numberDiff line numberDiff line change
@@ -20,65 +20,63 @@ main() {
2020
# linking with GNU LD
2121
for ex in "${examples[@]}"; do
2222
cargo rustc --target $TARGET --example $ex -- \
23-
-C link-arg=-nostartfiles \
24-
-C link-arg=-Wl,-Tlink.x
23+
-C linker=arm-none-eabi-ld \
24+
-C link-arg=-Tlink.x
2525

2626
cargo rustc --target $TARGET --example $ex --release -- \
27-
-C link-arg=-nostartfiles \
28-
-C link-arg=-Wl,-Tlink.x
27+
-C linker=arm-none-eabi-ld \
28+
-C link-arg=-Tlink.x
2929
done
3030
for ex in "${fail_examples[@]}"; do
3131
! cargo rustc --target $TARGET --example $ex -- \
32-
-C link-arg=-nostartfiles \
33-
-C link-arg=-Wl,-Tlink.x
32+
-C linker=arm-none-eabi-ld \
33+
-C link-arg=-Tlink.x
3434

3535
! cargo rustc --target $TARGET --example $ex --release -- \
36-
-C link-arg=-nostartfiles \
37-
-C link-arg=-Wl,-Tlink.x
36+
-C linker=arm-none-eabi-ld \
37+
-C link-arg=-Tlink.x
3838
done
3939

4040
cargo rustc --target $TARGET --example device --features device -- \
41-
-C link-arg=-nostartfiles \
42-
-C link-arg=-Wl,-Tlink.x
41+
-C linker=arm-none-eabi-ld \
42+
-C link-arg=-Tlink.x
4343

4444
cargo rustc --target $TARGET --example device --features device --release -- \
45-
-C link-arg=-nostartfiles \
46-
-C link-arg=-Wl,-Tlink.x
45+
-C linker=arm-none-eabi-ld \
46+
-C link-arg=-Tlink.x
4747

4848
# linking with rustc's LLD
4949
for ex in "${examples[@]}"; do
5050
cargo rustc --target $TARGET --example $ex -- \
5151
-C linker=rust-lld \
52-
-Z linker-flavor=ld.lld \
5352
-C link-arg=-Tlink.x
5453

5554
cargo rustc --target $TARGET --example $ex --release -- \
5655
-C linker=rust-lld \
57-
-Z linker-flavor=ld.lld \
5856
-C link-arg=-Tlink.x
5957
done
6058
for ex in "${fail_examples[@]}"; do
6159
! cargo rustc --target $TARGET --example $ex -- \
6260
-C linker=rust-lld \
63-
-Z linker-flavor=ld.lld \
6461
-C link-arg=-Tlink.x
6562

6663
! cargo rustc --target $TARGET --example $ex --release -- \
6764
-C linker=rust-lld \
68-
-Z linker-flavor=ld.lld \
6965
-C link-arg=-Tlink.x
7066
done
7167

7268
cargo rustc --target $TARGET --example device --features device -- \
7369
-C linker=rust-lld \
74-
-Z linker-flavor=ld.lld \
7570
-C link-arg=-Tlink.x
7671

7772
cargo rustc --target $TARGET --example device --features device --release -- \
7873
-C linker=rust-lld \
79-
-Z linker-flavor=ld.lld \
8074
-C link-arg=-Tlink.x
8175
fi
76+
77+
if [ $TARGET = x86_64-unknown-linux-gnu ]; then
78+
./check-blobs.sh
79+
fi
8280
}
8381

8482
main

0 commit comments

Comments
 (0)