Skip to content

Commit e5ee4e1

Browse files
committed
makefile.toml: one workspace and cargo metadata
For kit builds, Buildsys will need to understand the cargo dependency graph. This requires a call to cargo metadata which, for efficiency sake, we do only once before calling cargo build. This commit updates Makefile.toml to provide that information to Buildsys. Additionally, we want to have one workspace at the top-level of the Twoliter project which includes all packages, kits and variants. This commit also includes changes to the Makefile.toml to support a single workspace.
1 parent b199154 commit e5ee4e1

File tree

1 file changed

+47
-17
lines changed

1 file changed

+47
-17
lines changed

twoliter/embedded/Makefile.toml

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[config]
22
skip_core_tasks = true
3+
default_to_workspace = false
34

45
[env]
56
# The directory into which Twoliter has installed tools (e.g. buildsys,
@@ -15,6 +16,8 @@ BUILDSYS_IMAGES_DIR = "${BUILDSYS_BUILD_DIR}/images"
1516
BUILDSYS_TOOLS_DIR = "${BUILDSYS_ROOT_DIR}/tools"
1617
BUILDSYS_SOURCES_DIR = "${BUILDSYS_ROOT_DIR}/sources"
1718
BUILDSYS_SBKEYS_DIR = "${BUILDSYS_ROOT_DIR}/sbkeys"
19+
BUILDSYS_METADATA_DIR = "${BUILDSYS_BUILD_DIR}/metadata"
20+
BUILDSYS_CARGO_METADATA_PATH = "${BUILDSYS_METADATA_DIR}/cargo_metadata.json"
1821
BUILDSYS_SBKEYS_PROFILE = { script = ['echo "${BUILDSYS_SBKEYS_PROFILE:-local}"'] }
1922
BUILDSYS_TIMESTAMP = { script = ["date +%s"] }
2023
BUILDSYS_VERSION_BUILD = { script = ["git describe --always --dirty --exclude '*' || echo 00000000"] }
@@ -278,6 +281,7 @@ mkdir -p ${BUILDSYS_BUILD_DIR}
278281
mkdir -p ${BUILDSYS_OUTPUT_DIR}
279282
mkdir -p ${BUILDSYS_PACKAGES_DIR}
280283
mkdir -p ${BUILDSYS_STATE_DIR}
284+
mkdir -p ${BUILDSYS_METADATA_DIR}
281285
mkdir -p ${GO_MOD_CACHE}
282286
'''
283287
]
@@ -321,10 +325,12 @@ dependencies = ["setup"]
321325
script_runner = "bash"
322326
script = [
323327
'''
324-
for ws in sources variants; do
325-
[ -d "${ws}" ] || continue
326-
cargo fetch --locked --manifest-path ${ws}/Cargo.toml
327-
done
328+
if [ -f "${BUILDSYS_SOURCES_DIR}/Cargo.toml" ]; then
329+
cargo fetch --locked --manifest-path "${BUILDSYS_SOURCES_DIR}/Cargo.toml"
330+
fi
331+
332+
cargo fetch --locked --manifest-path "${BUILDSYS_ROOT_DIR}/Cargo.toml"
333+
328334
chmod -R o+r ${CARGO_HOME}
329335
'''
330336
]
@@ -727,9 +733,26 @@ docker run --rm \
727733
'''
728734
]
729735

736+
# Reads the project's workspace Cargo dependency graph to a json file. Needed by buildsys when
737+
# building packages, kits and variants.
738+
[tasks.cargo-metadata]
739+
dependencies = ["setup"]
740+
script_runner = "bash"
741+
script = [
742+
'''
743+
rm -f "${BUILDSYS_CARGO_METADATA_PATH}"
744+
cargo metadata \
745+
--format-version 1 \
746+
--manifest-path "${BUILDSYS_ROOT_DIR}/Cargo.toml" \
747+
--offline \
748+
--all-features \
749+
> "${BUILDSYS_CARGO_METADATA_PATH}"
750+
'''
751+
]
752+
730753
# Builds a package including its build-time and runtime dependency packages.
731754
[tasks.build-package]
732-
dependencies = ["check-cargo-version", "fetch-sdk", "publish-setup", "fetch-licenses"]
755+
dependencies = ["check-cargo-version", "fetch-sdk", "publish-setup", "fetch-licenses", "cargo-metadata"]
733756
script_runner = "bash"
734757
script = [
735758
'''
@@ -757,13 +780,12 @@ cargo build \
757780
${CARGO_BUILD_ARGS} \
758781
${CARGO_MAKE_CARGO_ARGS} \
759782
${CARGO_MAKE_CARGO_LIMIT_JOBS} \
760-
--manifest-path "variants/Cargo.toml" \
761-
--package "${PACKAGE}"
783+
--manifest-path "${BUILDSYS_ROOT_DIR}/packages/${PACKAGE}/Cargo.toml"
762784
'''
763785
]
764786

765787
[tasks.build-variant]
766-
dependencies = ["fetch-sdk", "build-sbkeys", "publish-setup"]
788+
dependencies = ["fetch-sdk", "build-sbkeys", "publish-setup", "cargo-metadata"]
767789
script = [
768790
'''
769791
export PATH="${TWOLITER_TOOLS_DIR}:${PATH}"
@@ -777,7 +799,7 @@ export BUILDSYS_VARIANT_FLAVOR="${BUILDSYS_VARIANT_FLAVOR}"
777799
778800
# Save built artifacts for each architecture. We don't set this everywhere
779801
# because we build host tools with cargo as well, like buildsys and pubsys.
780-
export CARGO_TARGET_DIR=${BUILDSYS_ROOT_DIR}/variants/target/${BUILDSYS_ARCH}
802+
export CARGO_TARGET_DIR=${BUILDSYS_ROOT_DIR}/target/${BUILDSYS_ARCH}
781803
782804
rm -rf "${BUILDSYS_OUTPUT_DIR}/latest"
783805
cargo build \
@@ -1471,16 +1493,20 @@ dependencies = [
14711493
"clean-repos",
14721494
"clean-state",
14731495
"clean-tools",
1496+
"clean-metadata",
14741497
]
14751498

14761499
[tasks.clean-sources]
14771500
script_runner = "bash"
14781501
script = [
14791502
'''
1480-
for ws in sources; do
1481-
[ -d "${ws}" ] || continue
1482-
cargo clean --manifest-path ${ws}/Cargo.toml
1483-
done
1503+
1504+
if [ -f "${BUILDSYS_SOURCES_DIR}/Cargo.toml" ]; then
1505+
cargo clean --manifest-path "${BUILDSYS_SOURCES_DIR}/Cargo.toml"
1506+
fi
1507+
1508+
cargo clean --manifest-path "${BUILDSYS_ROOT_DIR}/Cargo.toml"
1509+
14841510
rm -f ${BUILDSYS_TOOLS_DIR}/bin/*
14851511
'''
14861512
]
@@ -1489,10 +1515,6 @@ rm -f ${BUILDSYS_TOOLS_DIR}/bin/*
14891515
script_runner = "bash"
14901516
script = [
14911517
'''
1492-
for ws in variants; do
1493-
[ -d "${ws}" ] || continue
1494-
cargo clean --manifest-path ${ws}/Cargo.toml
1495-
done
14961518
rm -rf ${BUILDSYS_PACKAGES_DIR}
14971519
'''
14981520
]
@@ -1531,6 +1553,14 @@ fi
15311553
'''
15321554
]
15331555

1556+
[tasks.clean-metadata]
1557+
script_runner = "bash"
1558+
script = [
1559+
'''
1560+
rm -rf "${BUILDSYS_METADATA_DIR}"
1561+
'''
1562+
]
1563+
15341564
# Deletes cached code used for Bottlerocket builds
15351565
[tasks.purge-cache]
15361566
dependencies = [

0 commit comments

Comments
 (0)