Skip to content

Commit

Permalink
checks: add tests for building crates using workspace inheritance (ip…
Browse files Browse the repository at this point in the history
  • Loading branch information
ipetkov authored Oct 23, 2022
1 parent bdea451 commit 6b86495
Show file tree
Hide file tree
Showing 27 changed files with 199 additions and 0 deletions.
5 changes: 5 additions & 0 deletions checks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
1 change: 1 addition & 0 deletions checks/mkDummySrcTests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
])
19 changes: 19 additions & 0 deletions checks/mkDummySrcTests/workspace-inheritance/expected/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[workspace]
members = ["print"]

[workspace.package]
edition = "2021"
version = "0.2.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
build = "cranespecific-dummy.rs"
name = "hello"

[package.edition]
workspace = true

[package.version]
workspace = true
Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
build = "cranespecific-dummy.rs"
name = "world"

[package.edition]
workspace = true

[package.version]
workspace = true
Original file line number Diff line number Diff line change
@@ -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() {}
19 changes: 19 additions & 0 deletions checks/mkDummySrcTests/workspace-inheritance/input/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions checks/mkDummySrcTests/workspace-inheritance/input/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
name = "hello"
version.workspace = true
edition.workspace = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn hello() -> &'static str {
"hello"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "print"
version.workspace = true
edition.workspace = true

[dependencies]
hello = { version = "*", path = "../hello" }
world = { version = "*", path = "../world" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("{}, {}", hello::hello(), world::world());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
name = "world"
version.workspace = true
edition.workspace = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn world() -> &'static str {
"world!"
}
19 changes: 19 additions & 0 deletions checks/workspace-inheritance/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions checks/workspace-inheritance/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 4 additions & 0 deletions checks/workspace-inheritance/hello/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
name = "hello"
version.workspace = true
edition.workspace = true
3 changes: 3 additions & 0 deletions checks/workspace-inheritance/hello/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn hello() -> &'static str {
"hello"
}
8 changes: 8 additions & 0 deletions checks/workspace-inheritance/print/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "print"
version.workspace = true
edition.workspace = true

[dependencies]
hello = { version = "*", path = "../hello" }
world = { version = "*", path = "../world" }
3 changes: 3 additions & 0 deletions checks/workspace-inheritance/print/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("{}, {}", hello::hello(), world::world());
}
4 changes: 4 additions & 0 deletions checks/workspace-inheritance/world/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
name = "world"
version.workspace = true
edition.workspace = true
3 changes: 3 additions & 0 deletions checks/workspace-inheritance/world/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn world() -> &'static str {
"world!"
}
1 change: 1 addition & 0 deletions lib/cleanCargoToml.nix
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ let
# "default-members"
# "exclude"
# "members"
# "package"
];

# https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down

0 comments on commit 6b86495

Please sign in to comment.