From 098879eb1ce3e0301e0dd17119bc7003b27cd07c Mon Sep 17 00:00:00 2001 From: Dave Tucker Date: Wed, 31 Aug 2022 14:55:39 +0000 Subject: [PATCH] Use default-members in Cargo workspace Adds bpf code to the workspace and is excluded by default. This allows for all deps to be managed in Cargo.lock and for cargo update to work as expected from the root. Similarly, rustfmt and clippy can operate on the whole workspace. Signed-off-by: Dave Tucker --- .cargo/config.toml | 30 +++++++++++++++++++++++++++++- .vim/coc-settings.json | 3 ++- .vscode/settings.json | 3 ++- Cargo.toml | 3 ++- xtask/src/run.rs | 2 +- {{project-name}}-ebpf/Cargo.toml | 21 +-------------------- 6 files changed, 37 insertions(+), 25 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index f0ccbc9..1ea1161 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,30 @@ [alias] -xtask = "run --package xtask --" \ No newline at end of file +xtask = "run --package xtask --" + +# this should migrate to cargo per-target profiles when it is implemented + +[target.bpfel-unknown-none] +rustflags = [ + "-C", "panic=abort", + "-C", "lto=yes", + "-C", "embed-bitcode=yes", + "-C", "debuginfo=2", + "-C", "opt-level=3", + "-C", "codegen-units=1", + "-C", "debug-assertions=no", + "-C", "overflow-checks=no", + "-C", "incremental=no", +] + +[target.bpfeb-unknown-none] +rustflags = [ + "-C", "panic=abort", + "-C", "lto=yes", + "-C", "embed-bitcode=yes", + "-C", "debuginfo=2", + "-C", "opt-level=3", + "-C", "codegen-units=1", + "-C", "debug-assertions=no", + "-C", "overflow-checks=no", + "-C", "incremental=no", +] \ No newline at end of file diff --git a/.vim/coc-settings.json b/.vim/coc-settings.json index 6a1ec7d..07c919f 100644 --- a/.vim/coc-settings.json +++ b/.vim/coc-settings.json @@ -1,3 +1,4 @@ { - "rust-analyzer.linkedProjects": ["Cargo.toml", "{{project-name}}-ebpf/Cargo.toml"] + "rust-analyzer.checkOnSave.allTargets": false, + "rust-analyzer.checkOnSave.command": "clippy" } diff --git a/.vscode/settings.json b/.vscode/settings.json index 6a1ec7d..07c919f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,4 @@ { - "rust-analyzer.linkedProjects": ["Cargo.toml", "{{project-name}}-ebpf/Cargo.toml"] + "rust-analyzer.checkOnSave.allTargets": false, + "rust-analyzer.checkOnSave.command": "clippy" } diff --git a/Cargo.toml b/Cargo.toml index c386364..41bb2e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,3 @@ [workspace] -members = ["{{project-name}}", "{{project-name}}-common", "xtask"] +members = ["{{project-name}}", "{{project-name}}-ebpf", "{{project-name}}-common", "xtask"] +default-members = ["{{project-name}}", "{{project-name}}-common", "xtask"] diff --git a/xtask/src/run.rs b/xtask/src/run.rs index afa6928..5aab949 100644 --- a/xtask/src/run.rs +++ b/xtask/src/run.rs @@ -58,7 +58,7 @@ pub fn run(opts: Options) -> Result<(), anyhow::Error> { args.append(&mut run_args); // spawn the command - let err = Command::new(args.get(0).expect("No first argument")) + let err = Command::new(args.first().expect("No first argument")) .args(args.iter().skip(1)) .exec(); diff --git a/{{project-name}}-ebpf/Cargo.toml b/{{project-name}}-ebpf/Cargo.toml index 6b7c3e9..f48e4af 100644 --- a/{{project-name}}-ebpf/Cargo.toml +++ b/{{project-name}}-ebpf/Cargo.toml @@ -10,23 +10,4 @@ aya-log-ebpf = { git = "https://github.com/aya-rs/aya", branch = "main" } [[bin]] name = "{{ project-name }}" -path = "src/main.rs" - -[profile.dev] -opt-level = 3 -debug = false -debug-assertions = false -overflow-checks = false -lto = true -panic = "abort" -incremental = false -codegen-units = 1 -rpath = false - -[profile.release] -lto = true -panic = "abort" -codegen-units = 1 - -[workspace] -members = [] +path = "src/main.rs" \ No newline at end of file