Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a Cargo workspace to make builds reproducible and speed up CI. #1714

Merged
merged 20 commits into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
953a20f
Use a Cargo workspace for reproducible builds on a given machine.
gendx Mar 25, 2020
85dad25
Simplify cleaning - there's a single target folder per workspace.
gendx Mar 25, 2020
ee1849f
Simplify boards/Makefile.common - Cargo already finds the workspace's…
gendx Mar 25, 2020
f91c388
Fix documentation warnings.
gendx Mar 27, 2020
0170194
Rename arty-e21 chip & board to disambiguate them.
gendx Mar 27, 2020
77fd805
Fix tools/check_wildcard_imports.sh
gendx Mar 27, 2020
365e7aa
Simplify tools/build-all-docs.sh to fix Netlify.
gendx Mar 27, 2020
393bc6f
Update target/ path in Makefiles.
gendx Mar 27, 2020
49e3350
Remove unused TOCK_ARCH environment variable from Makefiles.
gendx Mar 27, 2020
0e6f1ee
Fix target/ folder in various files.
gendx Mar 27, 2020
86621cd
Rename MAKEFILE_PARENT_PATH -> TOCK_ROOT_DIRECTORY for clarity.
gendx Mar 27, 2020
23bd9a9
Merge branch 'master' into reproducible-workspace
gendx Mar 27, 2020
c9a48f0
Fix typo.
gendx Mar 27, 2020
4877605
Fix tools/post_size_changes_to_github.sh to support top-level target …
gendx Mar 30, 2020
0c0f4df
Move per-board linker flag to a 'cargo rustc' parameter to allow buil…
gendx Mar 30, 2020
529eb9e
Add documentation for RUSTFLAGS_FOR_BIN in Makefile.common.
gendx Apr 1, 2020
ab71573
Merge remote-tracking branch 'upstream/master' into reproducible-work…
gendx Apr 1, 2020
04cb360
Merge remote-tracking branch 'upstream/master' into reproducible-work…
gendx Apr 7, 2020
6f6911c
Merge branch 'master' into reproducible-workspace
gendx Apr 7, 2020
927cb37
Add stm32f3discovery board to the workspace.
gendx Apr 7, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 59 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[workspace]
members = [
"arch/cortex-m",
"arch/cortex-m0",
"arch/cortex-m3",
"arch/cortex-m4",
"arch/rv32i",
"boards/acd52832",
"boards/arty_e21",
"boards/hail",
"boards/hifive1",
"boards/imix",
"boards/launchxl",
"boards/nordic/nrf52840dk",
"boards/nordic/nrf52840_dongle",
"boards/nordic/nrf52dk",
"boards/nucleo_f429zi",
"boards/nucleo_f446re",
"boards/opentitan",
"capsules",
"chips/arty_e21_chip",
"chips/cc26x2",
"chips/e310x",
"chips/ibex",
"chips/lowrisc",
"chips/nrf52",
"chips/nrf52832",
"chips/nrf52840",
"chips/nrf5x",
"chips/sam4l",
"chips/sifive",
"chips/stm32f4xx",
"kernel",
"libraries/enum_primitive",
"libraries/riscv-csr",
"libraries/tock-cells",
"libraries/tock-register-interface",
"libraries/tock-rt0",
]
exclude = [
"tools/alert_codes",
"tools/sha256sum",
"tools/usb/bulk-echo",
"tools/usb/bulk-echo-fast",
"tools/usb/bulk-test",
"tools/usb/control-test",
]

[profile.dev]
panic = "abort"
lto = false
opt-level = "z"
debug = true

[profile.release]
panic = "abort"
lto = true
opt-level = "z"
debug = true
8 changes: 2 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,9 @@ audit:

.PHONY: clean
clean:
@for f in `./tools/list_archs.sh`; do echo "$$(tput bold)Clean arch/$$f"; cargo clean --manifest-path "arch/$$f/Cargo.toml" || exit 1; done
@for f in `./tools/list_chips.sh`; do echo "$$(tput bold)Clean chips/$$f"; cargo clean --manifest-path "chips/$$f/Cargo.toml" || exit 1; done
@for f in `./tools/list_boards.sh`; do echo "$$(tput bold)Clean boards/$$f"; $(MAKE) -C "boards/$$f" clean || exit 1; done
@echo "$$(tput bold)Clean top-level Cargo workspace" && cargo clean
@for f in `./tools/list_tools.sh`; do echo "$$(tput bold)Clean tools/$$f"; cargo clean --manifest-path "tools/$$f/Cargo.toml" || exit 1; done
@cd kernel && echo "$$(tput bold)Clean kernel" && cargo clean
@cd libraries/tock-cells && echo "$$(tput bold)Clean libraries/tock-cells" && cargo clean
@cd libraries/tock-register-interface && echo "$$(tput bold)Clean libraries/tock-register-interface" && cargo clean
@echo "$$(tput bold)Clean rustdoc" && rm -Rf doc/rustdoc

.PHONY: fmt format formatall
fmt format formatall:
Expand Down
98 changes: 63 additions & 35 deletions boards/Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
MAKEFLAGS += -r
MAKEFLAGS += -R

# The absolute path of the directory containing this `Makefile.common` file.
MAKEFILE_COMMON_PATH := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
MAKEFILE_PARENT_PATH := $(dir $(abspath $(MAKEFILE_COMMON_PATH)/..))

# The absolute path of Tock's root directory.
# This is currently the parent directory of MAKEFILE_COMMON_PATH.
TOCK_ROOT_DIRECTORY := $(dir $(abspath $(MAKEFILE_COMMON_PATH)))

# Common defaults that specific boards can override, but likely do not need to.
TOOLCHAIN ?= llvm
Expand All @@ -24,7 +28,28 @@ RUSTFLAGS_FOR_CARGO ?= \
-C linker-flavor=ld.lld \
-C relocation-model=dynamic-no-pic \
-C link-arg=-zmax-page-size=512 \
--remap-path-prefix=$(MAKEFILE_PARENT_PATH)= \
--remap-path-prefix=$(TOCK_ROOT_DIRECTORY)= \

# The following flags should only be passed to the board's binary crate, but
# not to any of its dependencies (the kernel, capsules, chips, etc.). The
# dependencies wouldn't use it, but because the link path is different for each
# board, Cargo wouldn't be able to cache builds of the dependencies.
#
# Indeed, as far as Cargo is concerned, building the kernel with
# `-C link-arg=-L/tock/boards/imix` is different than building the kernel with
# `-C link-arg=-L/tock/boards/hail`, so Cargo would have to rebuild the kernel
# for each board instead of caching it per board (even if in reality the same
# kernel is built because the link-arg isn't used by the kernel).
#
# Ultimately, this should move to the Cargo.toml, for example when
# https://github.com/rust-lang/cargo/pull/7811 is merged into Cargo.
#
# The difference between `RUSTFLAGS_FOR_CARGO` and `RUSTFLAGS_FOR_BIN` is that
# the former is forwarded to all the dependencies (being passed to cargo via
# the `RUSTFLAGS` environment variable), whereas the latter is only applied to
# the final binary crate (being passed as parameter to `cargo rustc`).
RUSTFLAGS_FOR_BIN ?= \
gendx marked this conversation as resolved.
Show resolved Hide resolved
-C link-arg=-L$(abspath .) \

# Disallow warnings for continuous integration builds. Disallowing them here
# ensures that warnings during testing won't prevent compilation from succeeding.
Expand Down Expand Up @@ -60,7 +85,7 @@ export TOCK_KERNEL_VERSION := $(shell git describe --tags --always 2> /dev/null
# Validate that rustup is new enough.
MINIMUM_RUSTUP_VERSION := 1.11.0
RUSTUP_VERSION := $(strip $(word 2, $(shell $(RUSTUP) --version)))
ifeq ($(shell $(MAKEFILE_COMMON_PATH)../tools/semver.sh $(RUSTUP_VERSION) \< $(MINIMUM_RUSTUP_VERSION)), true)
ifeq ($(shell $(TOCK_ROOT_DIRECTORY)tools/semver.sh $(RUSTUP_VERSION) \< $(MINIMUM_RUSTUP_VERSION)), true)
$(warning Required tool `$(RUSTUP)` is out-of-date.)
$(warning Running `$(RUSTUP) update` in 3 seconds (ctrl-c to cancel))
$(shell sleep 3s)
Expand Down Expand Up @@ -107,23 +132,26 @@ ifneq ($(V),)
$(info *******************************************************)
$(info TOCK KERNEL BUILD SYSTEM -- VERBOSE BUILD CONFIGURATION)
$(info *******************************************************)
$(info PLATFORM = $(PLATFORM))
$(info TARGET = $(TARGET))
$(info TOCK_KERNEL_VERSION = $(TOCK_KERNEL_VERSION))
$(info RUSTFLAGS_FOR_CARGO = $(RUSTFLAGS_FOR_CARGO))
$(info MAKEFLAGS = $(MAKEFLAGS))
$(info OBJDUMP_FLAGS = $(OBJDUMP_FLAGS))
$(info MAKEFILE_COMMON_PATH = $(MAKEFILE_COMMON_PATH))
$(info TOCK_ROOT_DIRECTORY = $(TOCK_ROOT_DIRECTORY))
$(info )
$(info PLATFORM = $(PLATFORM))
$(info TARGET = $(TARGET))
$(info TOCK_KERNEL_VERSION = $(TOCK_KERNEL_VERSION))
$(info RUSTFLAGS_FOR_CARGO = $(RUSTFLAGS_FOR_CARGO))
$(info MAKEFLAGS = $(MAKEFLAGS))
$(info OBJDUMP_FLAGS = $(OBJDUMP_FLAGS))
$(info )
$(info TOOLCHAIN = $(TOOLCHAIN))
$(info SIZE = $(SIZE))
$(info OBJCOPY = $(OBJCOPY))
$(info OBJDUMP = $(OBJDUMP))
$(info CARGO = $(CARGO))
$(info RUSTUP = $(RUSTUP))
$(info TOOLCHAIN = $(TOOLCHAIN))
$(info SIZE = $(SIZE))
$(info OBJCOPY = $(OBJCOPY))
$(info OBJDUMP = $(OBJDUMP))
$(info CARGO = $(CARGO))
$(info RUSTUP = $(RUSTUP))
$(info )
$(info cargo --version = $(shell $(CARGO) --version))
$(info rustc --version = $(shell rustc --version))
$(info rustup --version = $(shell $(RUSTUP) --version))
$(info cargo --version = $(shell $(CARGO) --version))
$(info rustc --version = $(shell rustc --version))
$(info rustup --version = $(shell $(RUSTUP) --version))
$(info *******************************************************)
$(info )
endif
Expand All @@ -139,27 +167,27 @@ all: release
# binary. This makes checking for Rust errors much faster.
.PHONY: check
check:
$(Q)RUSTFLAGS="$(RUSTFLAGS_FOR_CARGO)" $(CARGO) check --target=$(TARGET) $(VERBOSE) --release
$(Q)RUSTFLAGS="$(RUSTFLAGS_FOR_CARGO)" $(CARGO) check $(VERBOSE) --target=$(TARGET) --package $(PLATFORM) --release

.PHONY: clean
clean::
$(Q)$(CARGO) clean $(VERBOSE)

.PHONY: release
release: target/$(TARGET)/release/$(PLATFORM).bin
release: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).bin

.PHONY: debug
debug: target/$(TARGET)/debug/$(PLATFORM).bin
debug: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/debug/$(PLATFORM).bin

.PHONY: debug-lst
debug-lst: target/$(TARGET)/debug/$(PLATFORM).lst
debug-lst: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/debug/$(PLATFORM).lst

.PHONY: doc
doc: | target
$(Q)RUSTDOCFLAGS='-Z unstable-options --document-hidden-items' $(CARGO) doc $(VERBOSE) --release --target=$(TARGET)
$(Q)RUSTDOCFLAGS='-Z unstable-options --document-hidden-items' $(CARGO) doc $(VERBOSE) --release --package $(PLATFORM)

.PHONY: lst
lst: target/$(TARGET)/release/$(PLATFORM).lst
lst: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).lst

# Helper rule for showing the TARGET used by this board. Useful when building
# the documentation for all boards.
Expand All @@ -170,34 +198,34 @@ show-target:
# Support rules

target:
@mkdir -p target
@mkdir -p $(TOCK_ROOT_DIRECTORY)target

# Cargo outputs an elf file (just without a file extension)
%.elf: %
$(Q)cp $< $@

%.bin: %.elf $(MAKEFILE_COMMON_PATH)../tools/sha256sum/target/debug/sha256sum
%.bin: %.elf $(TOCK_ROOT_DIRECTORY)tools/sha256sum/target/debug/sha256sum
$(Q)$(OBJCOPY) --output-target=binary $< $@
$(Q)$(MAKEFILE_COMMON_PATH)../tools/sha256sum/target/debug/sha256sum $@
$(Q)$(TOCK_ROOT_DIRECTORY)tools/sha256sum/target/debug/sha256sum $@

%.lst: %.elf
$(Q)$(OBJDUMP) $(OBJDUMP_FLAGS) $< > $@


$(MAKEFILE_COMMON_PATH)../tools/sha256sum/target/debug/sha256sum:
$(Q)$(CARGO) build $(VERBOSE) --manifest-path $(MAKEFILE_COMMON_PATH)../tools/sha256sum/Cargo.toml
$(TOCK_ROOT_DIRECTORY)tools/sha256sum/target/debug/sha256sum:
$(Q)$(CARGO) build $(VERBOSE) --manifest-path $(TOCK_ROOT_DIRECTORY)tools/sha256sum/Cargo.toml


# Cargo-drivers
# We want to always invoke cargo (yay nested build systems), so these need to
# be phony, which means they can't be pattern rules.

.PHONY: target/$(TARGET)/release/$(PLATFORM)
target/$(TARGET)/release/$(PLATFORM):
$(Q)RUSTFLAGS="$(RUSTFLAGS_FOR_CARGO)" $(CARGO) build --target=$(TARGET) $(VERBOSE) --release
.PHONY: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM)
$(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM):
$(Q)RUSTFLAGS="$(RUSTFLAGS_FOR_CARGO)" $(CARGO) rustc $(VERBOSE) --target=$(TARGET) --package $(PLATFORM) --bin $(PLATFORM) --release -- $(RUSTFLAGS_FOR_BIN)
$(Q)$(SIZE) $@

.PHONY: target/$(TARGET)/debug/$(PLATFORM)
target/$(TARGET)/debug/$(PLATFORM):
$(Q)RUSTFLAGS="$(RUSTFLAGS_FOR_CARGO)" $(CARGO) build $(VERBOSE) --target=$(TARGET)
.PHONY: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/debug/$(PLATFORM)
$(TOCK_ROOT_DIRECTORY)target/$(TARGET)/debug/$(PLATFORM):
$(Q)RUSTFLAGS="$(RUSTFLAGS_FOR_CARGO)" $(CARGO) rustc $(VERBOSE) --target=$(TARGET) --package $(PLATFORM) --bin $(PLATFORM) -- $(RUSTFLAGS_FOR_BIN)
$(Q)$(SIZE) $@
12 changes: 0 additions & 12 deletions boards/acd52832/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,6 @@ authors = ["Tock Project Developers <tock-dev@googlegroups.com>"]
build = "build.rs"
edition = "2018"

[profile.dev]
panic = "abort"
lto = false
opt-level = "z"
debug = true

[profile.release]
panic = "abort"
lto = true
opt-level = "z"
debug = true

[dependencies]
components = { path = "../components" }
cortexm4 = { path = "../../arch/cortex-m4" }
Expand Down
3 changes: 1 addition & 2 deletions boards/acd52832/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Makefile for building the tock kernel for the nRF development kit

TOCK_ARCH=cortex-m4
TARGET=thumbv7em-none-eabi
PLATFORM=acd52832

Expand All @@ -20,5 +19,5 @@ TOCKLOADER_JTAG_FLAGS = --jlink --board nrf52dk

# Upload the kernel over JTAG
.PHONY: flash
flash: target/$(TARGET)/release/$(PLATFORM).bin
flash: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).bin
$(TOCKLOADER) $(TOCKLOADER_GENERAL_FLAGS) flash --address $(KERNEL_ADDRESS) $(TOCKLOADER_JTAG_FLAGS) $<
16 changes: 2 additions & 14 deletions boards/arty-e21/Cargo.toml → boards/arty_e21/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
[package]
name = "arty-e21"
name = "arty_e21"
version = "0.1.0"
authors = ["Tock Project Developers <tock-dev@googlegroups.com>"]
build = "build.rs"
edition = "2018"

[profile.dev]
panic = "abort"
lto = false
opt-level = "z"
debug = true

[profile.release]
panic = "abort"
lto = true
opt-level = "z"
debug = true

[dependencies]
components = { path = "../components" }
rv32i = { path = "../../arch/rv32i" }
capsules = { path = "../../capsules" }
kernel = { path = "../../kernel" }
arty_e21 = { path = "../../chips/arty_e21" }
arty_e21_chip = { path = "../../chips/arty_e21_chip" }
sifive = { path = "../../chips/sifive" }
6 changes: 3 additions & 3 deletions boards/arty-e21/Makefile → boards/arty_e21/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Makefile for building the tock kernel for the HiFive1 platform

TARGET=riscv32imac-unknown-none-elf
PLATFORM=arty-e21
PLATFORM=arty_e21

include ../Makefile.common

Expand All @@ -11,10 +11,10 @@ KERNEL_ADDRESS=0x400000
TOCKLOADER_OPENOCD_FLAGS = --openocd --board arty

.PHONY: flash-tockloader
flash-tockloader: target/$(TARGET)/release/$(PLATFORM).bin
flash-tockloader: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).bin
$(TOCKLOADER) $(TOCKLOADER_GENERAL_FLAGS) flash --address $(KERNEL_ADDRESS) $(TOCKLOADER_OPENOCD_FLAGS) $<

flash: target/$(TARGET)/release/$(PLATFORM).bin
flash: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).bin
openocd -f openocd/arty-openocd-digilent.cfg \
-c "init; jtagspi_init 0 openocd/bscan_spi_xc7a100t.bit; jtagspi_program $< 0x400000; shutdown"

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions boards/arty-e21/src/io.rs → boards/arty_e21/src/io.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use arty_e21;
use arty_e21_chip;
use core::fmt::Write;
use core::panic::PanicInfo;
use core::str;
Expand Down Expand Up @@ -34,15 +34,15 @@ impl IoWrite for Writer {
#[panic_handler]
pub unsafe extern "C" fn panic_fmt(pi: &PanicInfo) -> ! {
// turn off the non panic leds, just in case
let led_green = &arty_e21::gpio::PORT[19];
let led_green = &arty_e21_chip::gpio::PORT[19];
gpio::Pin::make_output(led_green);
gpio::Pin::set(led_green);

let led_blue = &arty_e21::gpio::PORT[21];
let led_blue = &arty_e21_chip::gpio::PORT[21];
gpio::Pin::make_output(led_blue);
gpio::Pin::set(led_blue);

let led_red = &mut led::LedLow::new(&mut arty_e21::gpio::PORT[22]);
let led_red = &mut led::LedLow::new(&mut arty_e21_chip::gpio::PORT[22]);
let writer = &mut WRITER;
debug::panic(
&mut [led_red],
Expand Down