Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable dependencies based on dep: features #252

Merged
merged 1 commit into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crate2nix/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2900,7 +2900,7 @@ rec {
len = builtins.stringLength prefix;
startsWithPrefix = builtins.substring 0 len feature == prefix;
in
feature == name || startsWithPrefix;
feature == name || feature == "dep:" + name || startsWithPrefix;

/* Returns the expanded features for the given inputFeatures by applying the
rules in featureMap.
Expand Down
2 changes: 1 addition & 1 deletion crate2nix/templates/nix/crate2nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ rec {
len = builtins.stringLength prefix;
startsWithPrefix = builtins.substring 0 len feature == prefix;
in
feature == name || startsWithPrefix;
feature == name || feature == "dep:" + name || startsWithPrefix;

/* Returns the expanded features for the given inputFeatures by applying the
rules in featureMap.
Expand Down
14 changes: 14 additions & 0 deletions sample_projects/bin_with_dep_features/Cargo.lock

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

12 changes: 12 additions & 0 deletions sample_projects/bin_with_dep_features/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "bin_with_dep_features"
version = "0.1.0"
authors = ["Faye Duxovni <[email protected]>"]
edition = "2018"

[dependencies]
"hello_world_lib" = { path = "../lib", optional = true }

[features]
default = ["use_lib"]
use_lib = ["dep:hello_world_lib"]
7 changes: 7 additions & 0 deletions sample_projects/bin_with_dep_features/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#[cfg(feature = "use_lib")]
use renamed_hello_world_lib;

fn main() {
#[cfg(feature = "use_lib")]
renamed_hello_world_lib::hello_world("bin_with_dep_features");
}
2 changes: 1 addition & 1 deletion sample_projects/bin_with_git_branch_dep/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ rec {
len = builtins.stringLength prefix;
startsWithPrefix = builtins.substring 0 len feature == prefix;
in
feature == name || startsWithPrefix;
feature == name || feature == "dep:" + name || startsWithPrefix;

/* Returns the expanded features for the given inputFeatures by applying the
rules in featureMap.
Expand Down
2 changes: 1 addition & 1 deletion sample_projects/bin_with_git_submodule_dep/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1915,7 +1915,7 @@ rec {
len = builtins.stringLength prefix;
startsWithPrefix = builtins.substring 0 len feature == prefix;
in
feature == name || startsWithPrefix;
feature == name || feature == "dep:" + name || startsWithPrefix;

/* Returns the expanded features for the given inputFeatures by applying the
rules in featureMap.
Expand Down
2 changes: 1 addition & 1 deletion sample_projects/codegen/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ rec {
len = builtins.stringLength prefix;
startsWithPrefix = builtins.substring 0 len feature == prefix;
in
feature == name || startsWithPrefix;
feature == name || feature == "dep:" + name || startsWithPrefix;

/* Returns the expanded features for the given inputFeatures by applying the
rules in featureMap.
Expand Down
2 changes: 1 addition & 1 deletion sample_projects/sub_dir_crates/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ rec {
len = builtins.stringLength prefix;
startsWithPrefix = builtins.substring 0 len feature == prefix;
in
feature == name || startsWithPrefix;
feature == name || feature == "dep:" + name || startsWithPrefix;

/* Returns the expanded features for the given inputFeatures by applying the
rules in featureMap.
Expand Down
7 changes: 7 additions & 0 deletions tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ let
expectedOutput = "Hello, bin_with_rerenamed_lib_dep!";
}

{
name = "bin_with_dep_features";
src = ./sample_projects;
cargoToml = "bin_with_dep_features/Cargo.toml";
expectedOutput = "Hello, bin_with_dep_features!";
}

{
name = "sub_dir_crates";
src = ./sample_projects/sub_dir_crates;
Expand Down