You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to set up a project that uses crane and rust-overlay to target thumbv6m-none-eabi for embedded development and x86_64-unknown-linux-gnu for desktop development. One crate targets should build an application only for ARM and another for x86_64 Linux, both using a common library.
I currently have the attached flake.nix and using cargo build works. My flake in this form does not work correctly though.
I'm not sure which files are read and used by crane or the cargo invocations in crane derivations and I am also unsure if the experimental per-package-target is a good idea. What is an idiomatic way of handling this multi-target workspace setup? flake.nix:
{description="Azimuth Drone Control System";inputs={nixpkgs.url="github:NixOS/nixpkgs/nixos-unstable";rust-overlay={url="github:oxalica/rust-overlay";inputs.nixpkgs.follows="nixpkgs";};crane.url="github:ipetkov/crane";flake-utils.url="github:numtide/flake-utils";advisory-db={url="github:rustsec/advisory-db";flake=false;};};outputs={self,nixpkgs,rust-overlay,crane,flake-utils,advisory-db,}:
flake-utils.lib.eachDefaultSystem(system: letinherit(pkgs)lib;pkgs=importnixpkgs{inheritsystem;overlays=[(importrust-overlay)];};rustToolchain=pkgs.rust-bin.fromRustupToolchainFile./rust-toolchain.toml;craneLib=(crane.mkLibpkgs).overrideToolchainrustToolchain;src=craneLib.cleanCargoSource./.;commonArgs={inheritsrc;strictDeps=true;buildInputs=[];cargoExtraArgs="--workspace --exclude azimuth-firmware-pico";};# Common args for embedded buildsembeddedArgs=commonArgs//{cargoExtraArgs="-p azimuth-firmware-pico";# Need --target thumbv6m-none-eabi ?};# Build artifacts for both targetscargoArtifacts={embedded=craneLib.buildDepsOnlyembeddedArgs;std=craneLib.buildDepsOnlycommonArgs;};individualCrateArgs=cargoArtifacts:
commonArgs//{inheritcargoArtifacts;inherit(craneLib.crateNameFromCargoToml{inheritsrc;})version;# NB: we disable tests since we'll run them all via cargo-nextestdoCheck=false;};fileSetForCrate=crate:
lib.fileset.toSource{root=./.;fileset=lib.fileset.unions[./Cargo.toml./Cargo.lock./memory.x(craneLib.fileset.commonCargoSources./crates/azimuth-core)# (craneLib.fileset.commonCargoSources ./crates/workspace-hack)(craneLib.fileset.commonCargoSourcescrate)];};# Build the top-level crates of the workspace as individual derivations.# This allows consumers to only depend on (and build) only what they need.# Though it is possible to build the entire workspace as a single derivation,# so this is left up to you on how to organize things## Note that the cargo workspace must define `workspace.members` using wildcards,# otherwise, omitting a crate (like we do below) will result in errors since# cargo won't be able to find the sources for all members.firmware-pico=craneLib.buildPackage((individualCrateArgscargoArtifacts.embedded)//{pname="azimuth-firmware-pico";src=fileSetForCrate./crates/azimuth-firmware-pico;});firmware-sim=craneLib.buildPackage((individualCrateArgscargoArtifacts.std)//{pname="azimuth-firmware-sim";cargoExtraArgs="-p azimuth-firmware-sim";src=fileSetForCrate./crates/azimuth-firmware-sim;});gui=craneLib.buildPackage((individualCrateArgscargoArtifacts.std)//{pname="azimuth-gui";cargoExtraArgs="-p azimuth-gui";src=fileSetForCrate./crates/azimuth-gui;});in{packages={inheritfirmware-picofirmware-simgui;default=self.packages.${system}.firmware-sim;all=pkgs.symlinkJoin{name="azimuth-all";paths=[firmware-picofirmware-simgui];};};apps={firmware-pico=flake-utils.lib.mkApp{drv=firmware-pico;};firmware-sim=flake-utils.lib.mkApp{drv=firmware-sim;};};checks={# Build the crates as part of `nix flake check` for convenienceinheritfirmware-picofirmware-simgui;# Run clippy (and deny all warnings) on the workspace source,# again, reusing the dependency artifacts from above.## Note that this is done as a separate derivation so that# we can block the CI if there are issues here, but not# prevent downstream consumers from building our crate by itself.clippy-embeded=craneLib.cargoClippy(embeddedArgs//{cargoArtifacts=cargoArtifacts.embedded;cargoClippyExtraArgs="-p azimuth-firmware-pico -- --deny warnings";});clippy-std=craneLib.cargoClippy(commonArgs//{cargoArtifacts=cargoArtifacts.std;cargoClippyExtraArgs="--package azimuth-gui --package azimuth-firmware-sim -- --deny warnings";});doc-embedded=craneLib.cargoDoc(embeddedArgs//{cargoArtifacts=cargoArtifacts.embedded;});doc-std=craneLib.cargoDoc(commonArgs//{cargoArtifacts=cargoArtifacts.std;});# Check formattingformat=craneLib.cargoFmt{inheritsrc;};tomlformat=craneLib.taploFmt{src=pkgs.lib.sources.sourceFilesBySufficessrc[".toml"];# taplo arguments can be further customized below as needed# taploExtraArgs = "--config ./taplo.toml";};# Audit dependenciesaudit=craneLib.cargoAudit{inheritsrcadvisory-db;};# Audit licensesdeny=craneLib.cargoDeny{inheritsrc;};# Run tests with cargo-nextest# Consider setting `doCheck = false` on other crate derivations# if you do not want the tests to run twicenextest=craneLib.cargoNextest(commonArgs//{inheritcargoArtifacts;partitions=1;partitionType="count";});# Ensure that cargo-hakari is up to datehakari=craneLib.mkCargoDerivation{inheritsrc;pname="hakari";cargoArtifacts=null;doInstallCargoArtifacts=false;buildPhaseCargoCommand='' cargo hakari generate --diff # workspace-hack Cargo.toml is up-to-date cargo hakari manage-deps --dry-run # all workspace crates depend on workspace-hack cargo hakari verify '';nativeBuildInputs=[pkgs.cargo-hakari];};};devShells.default=craneLib.devShell{# Inherit inputs from checks.checks=self.checks.${system};inputsFrom=[self.packages.${system}.firmware-picoself.packages.${system}.firmware-sim];buildInputs=withpkgs;[# Essential# rustToolchain # Rust compiler and standard toolsrust-analyzer# IDE support# Cargo toolscargo-hakari# For RP2040 developmentprobe-rs-tools# Flashing and debuggingelf2uf2-rs# Converts ELF files to UF2 for the Picopicotool# For Pico operations];};});}
and, just for completeness and because I myself have no idea what I am doing, other possibly relevant files: .cargo/config.toml:
[target.'cfg(all(target_arch="arm",target_os="none"))']
# probe-rs provides flashing and defmt via a hardware debugger, and stack unwind on panicrunner = "probe-rs run --chip RP2040 --protocol swd"linker = "flip-link"rustflags = [
"-C",
"link-arg=--nmagic",
"-C",
"link-arg=-Tlink.x",
"-C",
"link-arg=-Tdefmt.x",
# Code-size optimizations.# trap unreachable can save a lot of space, but requires nightly compiler.# uncomment the next line if you wish to enable it# "-Z", "trap-unreachable=no","-C",
"no-vectorize-loops",
]
[env]
DEFMT_LOG = "debug"
Cargo.toml:
[workspace]
members = [
"crates/azimuth-core",
"crates/azimuth-firmware-pico",
"crates/azimuth-firmware-sim",
"crates/azimuth-gui",
]
resolver = "2"
[workspace.package]
version = "0.1.0"edition = "2021"authors = ["Maximilian Dietrich <m.dietrich16@web.de>"]
license = "MIT OR Apache-2.0"
[workspace.metadata.crane]
name = "azimuth"
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am trying to set up a project that uses crane and rust-overlay to target
thumbv6m-none-eabi
for embedded development andx86_64-unknown-linux-gnu
for desktop development. One crate targets should build an application only for ARM and another for x86_64 Linux, both using a common library.I currently have the attached
flake.nix
and usingcargo build
works. My flake in this form does not work correctly though.I'm not sure which files are read and used by crane or the cargo invocations in crane derivations and I am also unsure if the experimental
per-package-target
is a good idea. What is an idiomatic way of handling this multi-target workspace setup?flake.nix
:and, just for completeness and because I myself have no idea what I am doing, other possibly relevant files:
.cargo/config.toml
:Cargo.toml
:crate/azimuth-firmware-pico/Cargo.toml
:crate/azimuth-firmware-sim/Cargo.toml
:crate/azimuth-core/Cargo.toml
:Beta Was this translation helpful? Give feedback.
All reactions