From 6b864957e1ac008cb04f8b53353b6fb8ea349c51 Mon Sep 17 00:00:00 2001 From: Ivan Petkov Date: Sun, 23 Oct 2022 15:56:18 -0700 Subject: [PATCH] checks: add tests for building crates using workspace inheritance (#147) --- checks/default.nix | 5 +++++ checks/mkDummySrcTests/default.nix | 1 + .../workspace-inheritance/expected/Cargo.lock | 19 +++++++++++++++++++ .../workspace-inheritance/expected/Cargo.toml | 6 ++++++ .../expected/hello/Cargo.toml | 9 +++++++++ .../expected/hello/src/lib.rs | 9 +++++++++ .../expected/print/Cargo.toml | 18 ++++++++++++++++++ .../expected/print/src/lib.rs | 9 +++++++++ .../expected/world/Cargo.toml | 9 +++++++++ .../expected/world/src/lib.rs | 9 +++++++++ .../workspace-inheritance/input/Cargo.lock | 19 +++++++++++++++++++ .../workspace-inheritance/input/Cargo.toml | 8 ++++++++ .../input/hello/Cargo.toml | 4 ++++ .../input/hello/src/lib.rs | 3 +++ .../input/print/Cargo.toml | 8 ++++++++ .../input/print/src/main.rs | 3 +++ .../input/world/Cargo.toml | 4 ++++ .../input/world/src/lib.rs | 3 +++ checks/workspace-inheritance/Cargo.lock | 19 +++++++++++++++++++ checks/workspace-inheritance/Cargo.toml | 8 ++++++++ checks/workspace-inheritance/hello/Cargo.toml | 4 ++++ checks/workspace-inheritance/hello/src/lib.rs | 3 +++ checks/workspace-inheritance/print/Cargo.toml | 8 ++++++++ .../workspace-inheritance/print/src/main.rs | 3 +++ checks/workspace-inheritance/world/Cargo.toml | 4 ++++ checks/workspace-inheritance/world/src/lib.rs | 3 +++ lib/cleanCargoToml.nix | 1 + 27 files changed, 199 insertions(+) create mode 100644 checks/mkDummySrcTests/workspace-inheritance/expected/Cargo.lock create mode 100644 checks/mkDummySrcTests/workspace-inheritance/expected/Cargo.toml create mode 100644 checks/mkDummySrcTests/workspace-inheritance/expected/hello/Cargo.toml create mode 100644 checks/mkDummySrcTests/workspace-inheritance/expected/hello/src/lib.rs create mode 100644 checks/mkDummySrcTests/workspace-inheritance/expected/print/Cargo.toml create mode 100644 checks/mkDummySrcTests/workspace-inheritance/expected/print/src/lib.rs create mode 100644 checks/mkDummySrcTests/workspace-inheritance/expected/world/Cargo.toml create mode 100644 checks/mkDummySrcTests/workspace-inheritance/expected/world/src/lib.rs create mode 100644 checks/mkDummySrcTests/workspace-inheritance/input/Cargo.lock create mode 100644 checks/mkDummySrcTests/workspace-inheritance/input/Cargo.toml create mode 100644 checks/mkDummySrcTests/workspace-inheritance/input/hello/Cargo.toml create mode 100644 checks/mkDummySrcTests/workspace-inheritance/input/hello/src/lib.rs create mode 100644 checks/mkDummySrcTests/workspace-inheritance/input/print/Cargo.toml create mode 100644 checks/mkDummySrcTests/workspace-inheritance/input/print/src/main.rs create mode 100644 checks/mkDummySrcTests/workspace-inheritance/input/world/Cargo.toml create mode 100644 checks/mkDummySrcTests/workspace-inheritance/input/world/src/lib.rs create mode 100644 checks/workspace-inheritance/Cargo.lock create mode 100644 checks/workspace-inheritance/Cargo.toml create mode 100644 checks/workspace-inheritance/hello/Cargo.toml create mode 100644 checks/workspace-inheritance/hello/src/lib.rs create mode 100644 checks/workspace-inheritance/print/Cargo.toml create mode 100644 checks/workspace-inheritance/print/src/main.rs create mode 100644 checks/workspace-inheritance/world/Cargo.toml create mode 100644 checks/workspace-inheritance/world/src/lib.rs diff --git a/checks/default.nix b/checks/default.nix index aa8f389d..870df1f1 100644 --- a/checks/default.nix +++ b/checks/default.nix @@ -326,6 +326,11 @@ in pname = "workspace"; }; + workspaceInheritance = lib.optionalAttrs (lib.versionAtLeast pkgs.cargo.version "1.64.0") (myLib.buildPackage { + src = myLib.cleanCargoSource ./workspace-inheritance; + pname = "workspace-inheritance"; + }); + workspaceRoot = myLib.buildPackage { src = myLib.cleanCargoSource ./workspace-root; pname = "workspace-root"; diff --git a/checks/mkDummySrcTests/default.nix b/checks/mkDummySrcTests/default.nix index a9129593..015470b8 100644 --- a/checks/mkDummySrcTests/default.nix +++ b/checks/mkDummySrcTests/default.nix @@ -66,6 +66,7 @@ linkFarmFromDrvs "cleanCargoToml" (lib.flatten [ (cmpDummySrc "single" ./single) (cmpDummySrc "single-alt" ./single-alt) (cmpDummySrc "workspace" ./workspace) + (cmpDummySrc "workspace-inheritance" ./workspace-inheritance) customizedDummy ]) diff --git a/checks/mkDummySrcTests/workspace-inheritance/expected/Cargo.lock b/checks/mkDummySrcTests/workspace-inheritance/expected/Cargo.lock new file mode 100644 index 00000000..ef3e794c --- /dev/null +++ b/checks/mkDummySrcTests/workspace-inheritance/expected/Cargo.lock @@ -0,0 +1,19 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "hello" +version = "0.2.0" + +[[package]] +name = "print" +version = "0.2.0" +dependencies = [ + "hello", + "world", +] + +[[package]] +name = "world" +version = "0.2.0" diff --git a/checks/mkDummySrcTests/workspace-inheritance/expected/Cargo.toml b/checks/mkDummySrcTests/workspace-inheritance/expected/Cargo.toml new file mode 100644 index 00000000..f30c7d10 --- /dev/null +++ b/checks/mkDummySrcTests/workspace-inheritance/expected/Cargo.toml @@ -0,0 +1,6 @@ +[workspace] +members = ["print"] + +[workspace.package] +edition = "2021" +version = "0.2.0" diff --git a/checks/mkDummySrcTests/workspace-inheritance/expected/hello/Cargo.toml b/checks/mkDummySrcTests/workspace-inheritance/expected/hello/Cargo.toml new file mode 100644 index 00000000..dbfb316d --- /dev/null +++ b/checks/mkDummySrcTests/workspace-inheritance/expected/hello/Cargo.toml @@ -0,0 +1,9 @@ +[package] +build = "cranespecific-dummy.rs" +name = "hello" + +[package.edition] +workspace = true + +[package.version] +workspace = true diff --git a/checks/mkDummySrcTests/workspace-inheritance/expected/hello/src/lib.rs b/checks/mkDummySrcTests/workspace-inheritance/expected/hello/src/lib.rs new file mode 100644 index 00000000..c204faae --- /dev/null +++ b/checks/mkDummySrcTests/workspace-inheritance/expected/hello/src/lib.rs @@ -0,0 +1,9 @@ +#![allow(dead_code)] +#![cfg_attr(target_os = "none", no_std)] + +#[cfg_attr(target_os = "none", panic_handler)] +fn panic(_info: &::core::panic::PanicInfo<'_>) -> ! { + loop {} +} + +pub fn main() {} diff --git a/checks/mkDummySrcTests/workspace-inheritance/expected/print/Cargo.toml b/checks/mkDummySrcTests/workspace-inheritance/expected/print/Cargo.toml new file mode 100644 index 00000000..0372e165 --- /dev/null +++ b/checks/mkDummySrcTests/workspace-inheritance/expected/print/Cargo.toml @@ -0,0 +1,18 @@ +[dependencies] +[dependencies.hello] +path = "../hello" +version = "*" + +[dependencies.world] +path = "../world" +version = "*" + +[package] +build = "cranespecific-dummy.rs" +name = "print" + +[package.edition] +workspace = true + +[package.version] +workspace = true diff --git a/checks/mkDummySrcTests/workspace-inheritance/expected/print/src/lib.rs b/checks/mkDummySrcTests/workspace-inheritance/expected/print/src/lib.rs new file mode 100644 index 00000000..c204faae --- /dev/null +++ b/checks/mkDummySrcTests/workspace-inheritance/expected/print/src/lib.rs @@ -0,0 +1,9 @@ +#![allow(dead_code)] +#![cfg_attr(target_os = "none", no_std)] + +#[cfg_attr(target_os = "none", panic_handler)] +fn panic(_info: &::core::panic::PanicInfo<'_>) -> ! { + loop {} +} + +pub fn main() {} diff --git a/checks/mkDummySrcTests/workspace-inheritance/expected/world/Cargo.toml b/checks/mkDummySrcTests/workspace-inheritance/expected/world/Cargo.toml new file mode 100644 index 00000000..628c3c2b --- /dev/null +++ b/checks/mkDummySrcTests/workspace-inheritance/expected/world/Cargo.toml @@ -0,0 +1,9 @@ +[package] +build = "cranespecific-dummy.rs" +name = "world" + +[package.edition] +workspace = true + +[package.version] +workspace = true diff --git a/checks/mkDummySrcTests/workspace-inheritance/expected/world/src/lib.rs b/checks/mkDummySrcTests/workspace-inheritance/expected/world/src/lib.rs new file mode 100644 index 00000000..c204faae --- /dev/null +++ b/checks/mkDummySrcTests/workspace-inheritance/expected/world/src/lib.rs @@ -0,0 +1,9 @@ +#![allow(dead_code)] +#![cfg_attr(target_os = "none", no_std)] + +#[cfg_attr(target_os = "none", panic_handler)] +fn panic(_info: &::core::panic::PanicInfo<'_>) -> ! { + loop {} +} + +pub fn main() {} diff --git a/checks/mkDummySrcTests/workspace-inheritance/input/Cargo.lock b/checks/mkDummySrcTests/workspace-inheritance/input/Cargo.lock new file mode 100644 index 00000000..ef3e794c --- /dev/null +++ b/checks/mkDummySrcTests/workspace-inheritance/input/Cargo.lock @@ -0,0 +1,19 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "hello" +version = "0.2.0" + +[[package]] +name = "print" +version = "0.2.0" +dependencies = [ + "hello", + "world", +] + +[[package]] +name = "world" +version = "0.2.0" diff --git a/checks/mkDummySrcTests/workspace-inheritance/input/Cargo.toml b/checks/mkDummySrcTests/workspace-inheritance/input/Cargo.toml new file mode 100644 index 00000000..23a95fb2 --- /dev/null +++ b/checks/mkDummySrcTests/workspace-inheritance/input/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] +# NB: hello and world are intentionally left out cargo will +# promote them to members since they are listed as path deps +members = ["print"] + +[workspace.package] +edition = "2021" +version = "0.2.0" diff --git a/checks/mkDummySrcTests/workspace-inheritance/input/hello/Cargo.toml b/checks/mkDummySrcTests/workspace-inheritance/input/hello/Cargo.toml new file mode 100644 index 00000000..0adbbc68 --- /dev/null +++ b/checks/mkDummySrcTests/workspace-inheritance/input/hello/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "hello" +version.workspace = true +edition.workspace = true diff --git a/checks/mkDummySrcTests/workspace-inheritance/input/hello/src/lib.rs b/checks/mkDummySrcTests/workspace-inheritance/input/hello/src/lib.rs new file mode 100644 index 00000000..8fd0518e --- /dev/null +++ b/checks/mkDummySrcTests/workspace-inheritance/input/hello/src/lib.rs @@ -0,0 +1,3 @@ +pub fn hello() -> &'static str { + "hello" +} diff --git a/checks/mkDummySrcTests/workspace-inheritance/input/print/Cargo.toml b/checks/mkDummySrcTests/workspace-inheritance/input/print/Cargo.toml new file mode 100644 index 00000000..469b5fae --- /dev/null +++ b/checks/mkDummySrcTests/workspace-inheritance/input/print/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "print" +version.workspace = true +edition.workspace = true + +[dependencies] +hello = { version = "*", path = "../hello" } +world = { version = "*", path = "../world" } diff --git a/checks/mkDummySrcTests/workspace-inheritance/input/print/src/main.rs b/checks/mkDummySrcTests/workspace-inheritance/input/print/src/main.rs new file mode 100644 index 00000000..4e560bf1 --- /dev/null +++ b/checks/mkDummySrcTests/workspace-inheritance/input/print/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("{}, {}", hello::hello(), world::world()); +} diff --git a/checks/mkDummySrcTests/workspace-inheritance/input/world/Cargo.toml b/checks/mkDummySrcTests/workspace-inheritance/input/world/Cargo.toml new file mode 100644 index 00000000..65a44737 --- /dev/null +++ b/checks/mkDummySrcTests/workspace-inheritance/input/world/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "world" +version.workspace = true +edition.workspace = true diff --git a/checks/mkDummySrcTests/workspace-inheritance/input/world/src/lib.rs b/checks/mkDummySrcTests/workspace-inheritance/input/world/src/lib.rs new file mode 100644 index 00000000..45475d53 --- /dev/null +++ b/checks/mkDummySrcTests/workspace-inheritance/input/world/src/lib.rs @@ -0,0 +1,3 @@ +pub fn world() -> &'static str { + "world!" +} diff --git a/checks/workspace-inheritance/Cargo.lock b/checks/workspace-inheritance/Cargo.lock new file mode 100644 index 00000000..ef3e794c --- /dev/null +++ b/checks/workspace-inheritance/Cargo.lock @@ -0,0 +1,19 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "hello" +version = "0.2.0" + +[[package]] +name = "print" +version = "0.2.0" +dependencies = [ + "hello", + "world", +] + +[[package]] +name = "world" +version = "0.2.0" diff --git a/checks/workspace-inheritance/Cargo.toml b/checks/workspace-inheritance/Cargo.toml new file mode 100644 index 00000000..23a95fb2 --- /dev/null +++ b/checks/workspace-inheritance/Cargo.toml @@ -0,0 +1,8 @@ +[workspace] +# NB: hello and world are intentionally left out cargo will +# promote them to members since they are listed as path deps +members = ["print"] + +[workspace.package] +edition = "2021" +version = "0.2.0" diff --git a/checks/workspace-inheritance/hello/Cargo.toml b/checks/workspace-inheritance/hello/Cargo.toml new file mode 100644 index 00000000..0adbbc68 --- /dev/null +++ b/checks/workspace-inheritance/hello/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "hello" +version.workspace = true +edition.workspace = true diff --git a/checks/workspace-inheritance/hello/src/lib.rs b/checks/workspace-inheritance/hello/src/lib.rs new file mode 100644 index 00000000..8fd0518e --- /dev/null +++ b/checks/workspace-inheritance/hello/src/lib.rs @@ -0,0 +1,3 @@ +pub fn hello() -> &'static str { + "hello" +} diff --git a/checks/workspace-inheritance/print/Cargo.toml b/checks/workspace-inheritance/print/Cargo.toml new file mode 100644 index 00000000..469b5fae --- /dev/null +++ b/checks/workspace-inheritance/print/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "print" +version.workspace = true +edition.workspace = true + +[dependencies] +hello = { version = "*", path = "../hello" } +world = { version = "*", path = "../world" } diff --git a/checks/workspace-inheritance/print/src/main.rs b/checks/workspace-inheritance/print/src/main.rs new file mode 100644 index 00000000..4e560bf1 --- /dev/null +++ b/checks/workspace-inheritance/print/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("{}, {}", hello::hello(), world::world()); +} diff --git a/checks/workspace-inheritance/world/Cargo.toml b/checks/workspace-inheritance/world/Cargo.toml new file mode 100644 index 00000000..65a44737 --- /dev/null +++ b/checks/workspace-inheritance/world/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "world" +version.workspace = true +edition.workspace = true diff --git a/checks/workspace-inheritance/world/src/lib.rs b/checks/workspace-inheritance/world/src/lib.rs new file mode 100644 index 00000000..45475d53 --- /dev/null +++ b/checks/workspace-inheritance/world/src/lib.rs @@ -0,0 +1,3 @@ +pub fn world() -> &'static str { + "world!" +} diff --git a/lib/cleanCargoToml.nix b/lib/cleanCargoToml.nix index 9233f3e9..6529df7c 100644 --- a/lib/cleanCargoToml.nix +++ b/lib/cleanCargoToml.nix @@ -63,6 +63,7 @@ let # "default-members" # "exclude" # "members" + # "package" ]; # https://doc.rust-lang.org/cargo/reference/manifest.html