aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar bors[bot] <bors[bot]@users.noreply.github.com> 2018-08-26 21:23:35 +0000
committerGravatar bors[bot] <bors[bot]@users.noreply.github.com> 2018-08-26 21:23:35 +0000
commitb84d549dcbbb88286793fc3e7e1c8afbc2ca3a76 (patch)
treec4c2d2205ae9523631e2ff8e044923b24aadf4c8
parente790d9b8d9785502e05d70b1ddf0ed024cbf71d5 (diff)
parent1dfbc864d32cc49ffaadb8ff97ede9df00cb0224 (diff)
downloadcortex-m-b84d549dcbbb88286793fc3e7e1c8afbc2ca3a76.tar.gz
cortex-m-b84d549dcbbb88286793fc3e7e1c8afbc2ca3a76.tar.zst
cortex-m-b84d549dcbbb88286793fc3e7e1c8afbc2ca3a76.zip
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 rust-embedded/cortex-m#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>
-rw-r--r--cortex-m-rt/.gitignore3
-rw-r--r--cortex-m-rt/.travis.yml17
-rw-r--r--cortex-m-rt/Cargo.toml3
-rw-r--r--cortex-m-rt/asm.s1
-rwxr-xr-xcortex-m-rt/assemble.sh19
-rw-r--r--cortex-m-rt/bin/thumbv6m-none-eabi.abin0 -> 886 bytes
-rw-r--r--cortex-m-rt/bin/thumbv7em-none-eabi.abin0 -> 886 bytes
-rw-r--r--cortex-m-rt/bin/thumbv7em-none-eabihf.abin0 -> 886 bytes
-rw-r--r--cortex-m-rt/bin/thumbv7m-none-eabi.abin0 -> 886 bytes
-rw-r--r--cortex-m-rt/build.rs11
-rwxr-xr-xcortex-m-rt/check-blobs.sh21
-rw-r--r--cortex-m-rt/ci/install.sh8
-rw-r--r--cortex-m-rt/ci/script.sh34
13 files changed, 71 insertions, 46 deletions
diff --git a/cortex-m-rt/.gitignore b/cortex-m-rt/.gitignore
index 6dc3db1..c71d6db 100644
--- a/cortex-m-rt/.gitignore
+++ b/cortex-m-rt/.gitignore
@@ -1,3 +1,6 @@
**/*.rs.bk
Cargo.lock
+bin/*.after
+bin/*.before
+bin/*.o
target/
diff --git a/cortex-m-rt/.travis.yml b/cortex-m-rt/.travis.yml
index 7381b73..caa29ef 100644
--- a/cortex-m-rt/.travis.yml
+++ b/cortex-m-rt/.travis.yml
@@ -3,13 +3,10 @@ language: rust
matrix:
include:
- env: TARGET=x86_64-unknown-linux-gnu
- if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
-
- - env: TARGET=thumbv6m-none-eabi
rust: stable
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
- - env: TARGET=thumbv6m-none-eabi CC=clang
+ - env: TARGET=thumbv6m-none-eabi
rust: stable
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
@@ -17,26 +14,14 @@ matrix:
rust: stable
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
- - env: TARGET=thumbv7m-none-eabi CC=clang
- rust: stable
- if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
-
- env: TARGET=thumbv7em-none-eabi
rust: stable
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
- - env: TARGET=thumbv7em-none-eabi CC=clang
- rust: stable
- if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
-
- env: TARGET=thumbv7em-none-eabihf
rust: stable
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
- - env: TARGET=thumbv7em-none-eabihf CC=clang
- rust: stable
- if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
-
- env: TARGET=thumbv6m-none-eabi
rust: nightly
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
diff --git a/cortex-m-rt/Cargo.toml b/cortex-m-rt/Cargo.toml
index 1ebcbb8..1cd9aaa 100644
--- a/cortex-m-rt/Cargo.toml
+++ b/cortex-m-rt/Cargo.toml
@@ -10,9 +10,6 @@ name = "cortex-m-rt"
repository = "https://github.com/japaric/cortex-m-rt"
version = "0.5.2"
-[build-dependencies]
-cc = "1.0.10"
-
[dependencies]
r0 = "0.2.1"
diff --git a/cortex-m-rt/asm.s b/cortex-m-rt/asm.s
index 2937be8..c7133c0 100644
--- a/cortex-m-rt/asm.s
+++ b/cortex-m-rt/asm.s
@@ -1,3 +1,4 @@
+ .section .text.HardFault
.global HardFault
.thumb_func
HardFault:
diff --git a/cortex-m-rt/assemble.sh b/cortex-m-rt/assemble.sh
new file mode 100755
index 0000000..f9ec7d8
--- /dev/null
+++ b/cortex-m-rt/assemble.sh
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+set -euxo pipefail
+
+# cflags taken from cc 1.0.22
+
+crate=cortex-m-rt
+
+arm-none-eabi-as -march=armv6s-m asm.s -o bin/$crate.o
+ar crs bin/thumbv6m-none-eabi.a bin/$crate.o
+
+arm-none-eabi-as -march=armv7-m asm.s -o bin/$crate.o
+ar crs bin/thumbv7m-none-eabi.a bin/$crate.o
+
+arm-none-eabi-as -march=armv7e-m asm.s -o bin/$crate.o
+ar crs bin/thumbv7em-none-eabi.a bin/$crate.o
+ar crs bin/thumbv7em-none-eabihf.a bin/$crate.o
+
+rm bin/$crate.o
diff --git a/cortex-m-rt/bin/thumbv6m-none-eabi.a b/cortex-m-rt/bin/thumbv6m-none-eabi.a
new file mode 100644
index 0000000..62ac317
--- /dev/null
+++ b/cortex-m-rt/bin/thumbv6m-none-eabi.a
Binary files differ
diff --git a/cortex-m-rt/bin/thumbv7em-none-eabi.a b/cortex-m-rt/bin/thumbv7em-none-eabi.a
new file mode 100644
index 0000000..ef9042f
--- /dev/null
+++ b/cortex-m-rt/bin/thumbv7em-none-eabi.a
Binary files differ
diff --git a/cortex-m-rt/bin/thumbv7em-none-eabihf.a b/cortex-m-rt/bin/thumbv7em-none-eabihf.a
new file mode 100644
index 0000000..ef9042f
--- /dev/null
+++ b/cortex-m-rt/bin/thumbv7em-none-eabihf.a
Binary files differ
diff --git a/cortex-m-rt/bin/thumbv7m-none-eabi.a b/cortex-m-rt/bin/thumbv7m-none-eabi.a
new file mode 100644
index 0000000..b93dae7
--- /dev/null
+++ b/cortex-m-rt/bin/thumbv7m-none-eabi.a
Binary files differ
diff --git a/cortex-m-rt/build.rs b/cortex-m-rt/build.rs
index fc53d79..8166b1b 100644
--- a/cortex-m-rt/build.rs
+++ b/cortex-m-rt/build.rs
@@ -1,18 +1,21 @@
-extern crate cc;
-
use std::env;
-use std::fs::File;
+use std::fs::{self, File};
use std::io::Write;
use std::path::PathBuf;
fn main() {
let target = env::var("TARGET").unwrap();
+ let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
has_fpu(&target);
let is_armv6m = is_armv6m(&target);
if target.starts_with("thumbv") {
- cc::Build::new().file("asm.s").compile("asm");
+ fs::copy(
+ format!("bin/{}.a", target),
+ out_dir.join("libcortex-m-rt.a"),
+ ).unwrap();
+ println!("cargo:rustc-link-lib=static=cortex-m-rt");
}
// Put the linker script somewhere the linker can find it
diff --git a/cortex-m-rt/check-blobs.sh b/cortex-m-rt/check-blobs.sh
new file mode 100755
index 0000000..94fde42
--- /dev/null
+++ b/cortex-m-rt/check-blobs.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+# Checks that the blobs are up to date with the committed assembly files
+
+set -euxo pipefail
+
+for lib in $(ls bin/*.a); do
+ filename=$(basename $lib)
+ arm-none-eabi-objdump -Cd $lib > bin/${filename%.a}.before
+done
+
+./assemble.sh
+
+for lib in $(ls bin/*.a); do
+ filename=$(basename $lib)
+ arm-none-eabi-objdump -Cd $lib > bin/${filename%.a}.after
+done
+
+for cksum in $(ls bin/*.after); do
+ diff -u $cksum ${cksum%.after}.before
+done
diff --git a/cortex-m-rt/ci/install.sh b/cortex-m-rt/ci/install.sh
index f211207..e63e805 100644
--- a/cortex-m-rt/ci/install.sh
+++ b/cortex-m-rt/ci/install.sh
@@ -3,13 +3,11 @@ set -euxo pipefail
main() {
if [ $TARGET != x86_64-unknown-linux-gnu ]; then
rustup target add $TARGET
+ fi
- if [ ${CC:-gcc} = gcc ]; then
- mkdir gcc
+ mkdir gcc
- 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
- fi
- fi
+ 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
}
main
diff --git a/cortex-m-rt/ci/script.sh b/cortex-m-rt/ci/script.sh
index 2e070bf..7d1cc67 100644
--- a/cortex-m-rt/ci/script.sh
+++ b/cortex-m-rt/ci/script.sh
@@ -20,65 +20,63 @@ main() {
# linking with GNU LD
for ex in "${examples[@]}"; do
cargo rustc --target $TARGET --example $ex -- \
- -C link-arg=-nostartfiles \
- -C link-arg=-Wl,-Tlink.x
+ -C linker=arm-none-eabi-ld \
+ -C link-arg=-Tlink.x
cargo rustc --target $TARGET --example $ex --release -- \
- -C link-arg=-nostartfiles \
- -C link-arg=-Wl,-Tlink.x
+ -C linker=arm-none-eabi-ld \
+ -C link-arg=-Tlink.x
done
for ex in "${fail_examples[@]}"; do
! cargo rustc --target $TARGET --example $ex -- \
- -C link-arg=-nostartfiles \
- -C link-arg=-Wl,-Tlink.x
+ -C linker=arm-none-eabi-ld \
+ -C link-arg=-Tlink.x
! cargo rustc --target $TARGET --example $ex --release -- \
- -C link-arg=-nostartfiles \
- -C link-arg=-Wl,-Tlink.x
+ -C linker=arm-none-eabi-ld \
+ -C link-arg=-Tlink.x
done
cargo rustc --target $TARGET --example device --features device -- \
- -C link-arg=-nostartfiles \
- -C link-arg=-Wl,-Tlink.x
+ -C linker=arm-none-eabi-ld \
+ -C link-arg=-Tlink.x
cargo rustc --target $TARGET --example device --features device --release -- \
- -C link-arg=-nostartfiles \
- -C link-arg=-Wl,-Tlink.x
+ -C linker=arm-none-eabi-ld \
+ -C link-arg=-Tlink.x
# linking with rustc's LLD
for ex in "${examples[@]}"; do
cargo rustc --target $TARGET --example $ex -- \
-C linker=rust-lld \
- -Z linker-flavor=ld.lld \
-C link-arg=-Tlink.x
cargo rustc --target $TARGET --example $ex --release -- \
-C linker=rust-lld \
- -Z linker-flavor=ld.lld \
-C link-arg=-Tlink.x
done
for ex in "${fail_examples[@]}"; do
! cargo rustc --target $TARGET --example $ex -- \
-C linker=rust-lld \
- -Z linker-flavor=ld.lld \
-C link-arg=-Tlink.x
! cargo rustc --target $TARGET --example $ex --release -- \
-C linker=rust-lld \
- -Z linker-flavor=ld.lld \
-C link-arg=-Tlink.x
done
cargo rustc --target $TARGET --example device --features device -- \
-C linker=rust-lld \
- -Z linker-flavor=ld.lld \
-C link-arg=-Tlink.x
cargo rustc --target $TARGET --example device --features device --release -- \
-C linker=rust-lld \
- -Z linker-flavor=ld.lld \
-C link-arg=-Tlink.x
fi
+
+ if [ $TARGET = x86_64-unknown-linux-gnu ]; then
+ ./check-blobs.sh
+ fi
}
main