Skip to content

Commit 813c2cb

Browse files
committed
2-stage sysroot. zephyr renamed to zephyr-core
Allows all crates built here to be provided in the sysroot by default so they do not have to be named in the app's Cargo.toml with relative path dependencies.
1 parent c101c05 commit 813c2cb

File tree

25 files changed

+296
-294
lines changed

25 files changed

+296
-294
lines changed

rust/build.sh

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,32 @@
33
HOST=$(rustc -vV | grep host: | cut -d ' ' -f 2)
44
VERSION="+nightly-2019-05-22"
55
CARGO_ARGS="${VERSION} -v build --target=${RUST_TARGET} --release"
6-
cargo ${CARGO_ARGS} --target-dir=${SYSROOT_BUILD} --manifest-path=./sysroot/Cargo.toml -p std
76

8-
SYSROOT_LIB="${SYSROOT}/lib/rustlib/${RUST_TARGET}/lib"
9-
SYSROOT_LIB_HOST="${SYSROOT}/lib/rustlib/${HOST}/lib"
7+
publish_sysroot() {
8+
local SYSROOT=$1
9+
local SYSROOT_LIB="${SYSROOT}/lib/rustlib/${RUST_TARGET}/lib"
10+
local SYSROOT_LIB_HOST="${SYSROOT}/lib/rustlib/${HOST}/lib"
11+
shift
12+
rm -rf ${SYSROOT}
13+
mkdir -p ${SYSROOT_LIB} ${SYSROOT_LIB_HOST}
1014

11-
copy_dir_if_changed() {
12-
mkdir -p $2
13-
if ! diff --brief --recursive $1 $2; then
14-
rm -r $2
15-
cp -a $1 $2
16-
fi
15+
for src in $@; do
16+
cp -a $src/${RUST_TARGET}/release/deps/. ${SYSROOT_LIB}
17+
cp -a $src/release/deps/. ${SYSROOT_LIB_HOST}
18+
done
1719
}
1820

19-
copy_dir_if_changed ${SYSROOT_BUILD}/${RUST_TARGET}/release/deps ${SYSROOT_LIB}
20-
copy_dir_if_changed ${SYSROOT_BUILD}/release/deps ${SYSROOT_LIB_HOST}
21+
# Build std
22+
cargo ${CARGO_ARGS} \
23+
--target-dir=${SYSROOT_BUILD}-stage1 \
24+
--manifest-path=./sysroot-stage1/Cargo.toml -p std
25+
publish_sysroot ${SYSROOT}-stage1 ${SYSROOT_BUILD}-stage1
26+
# Build Zephyr crates
27+
RUSTFLAGS="${RUSTFLAGS} --sysroot ${SYSROOT}-stage1" cargo ${CARGO_ARGS} \
28+
--target-dir=${SYSROOT_BUILD}-stage2 \
29+
--manifest-path=./sysroot-stage2/Cargo.toml
30+
31+
publish_sysroot ${SYSROOT} ${SYSROOT_BUILD}-stage1 ${SYSROOT_BUILD}-stage2
2132

2233
export RUSTFLAGS="${RUSTFLAGS} --sysroot ${SYSROOT}"
2334
cargo ${CARGO_ARGS} --target-dir=${APP_BUILD} --manifest-path=${CARGO_MANIFEST}

rust/sysroot/Cargo.lock renamed to rust/sysroot-stage1/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.
File renamed without changes.

rust/sysroot-stage2/Cargo.lock

Lines changed: 70 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/sysroot-stage2/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
authors = ["Tyler Hall <[email protected]>"]
3+
name = "sysroot"
4+
version = "0.0.0"
5+
6+
[dependencies.zephyr]
7+
path = "../zephyr"
8+
9+
[dependencies.zephyr-macros]
10+
path = "../zephyr-macros"
11+
12+
[dependencies.zephyr-logger]
13+
path = "../zephyr-logger"
14+
15+
[profile.release]
16+
lto = true
17+
panic = "abort"
18+
debug = true

rust/sysroot-stage2/src/lib.rs

Whitespace-only changes.
File renamed without changes.

rust/zephyr-core/Cargo.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[package]
2+
name = "zephyr-core"
3+
description = "Safe bindings to Zephyr kernel API (only using libcore)"
4+
version = "0.1.0"
5+
authors = ["Tyler Hall <[email protected]>"]
6+
edition = "2018"
7+
8+
[dependencies]
9+
libc = { path = "../libc" }
10+
11+
zephyr-sys = { path = "../zephyr-sys" }
12+
core = { version = '1.0.0', optional = true, package = 'rustc-std-workspace-core' }
13+
compiler_builtins = { version = '0.1.2', optional = true }
14+
derive_more = { version = '0.14.1', default-features = false, features = ['no_std'] }
15+
16+
[features]
17+
defaults = [ 'rustc-dep-of-std' ]
18+
rustc-dep-of-std = ['core', 'compiler_builtins/rustc-dep-of-std', 'zephyr-sys/rustc-dep-of-std', 'libc/rustc-dep-of-std']
19+
have_std = []

0 commit comments

Comments
 (0)