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

Add support for target_feature cfgs #142

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 3 additions & 0 deletions crate2nix/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
, rootFeatures ? [ "default" ]
# If true, throw errors instead of issueing deprecation warnings.
, strictDeprecation ? false
# Used for conditional compilation based on CPU feature detection.
, targetFeatures ? []
# Whether to perform release builds: longer compile times, faster binaries.
, release ? true
# Additional crate2nix configuration if it exists.
Expand Down Expand Up @@ -2467,6 +2469,7 @@ rec {
crateConfig.sha256;
}
);
extraRustcOpts = lib.lists.optional (targetFeatures != [ ]) "-C target-feature=${stdenv.lib.concatMapStringsSep "," (x: "+${x}") targetFeatures}";
inherit features dependencies buildDependencies crateRenames release;
}
);
Expand Down
9 changes: 9 additions & 0 deletions crate2nix/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ fn cfg_to_nix_expr(cfg: &CfgExpr) -> String {
let escaped_value = escape_nix_string(value);
result.push_str(&if key == "feature" {
format!("(builtins.elem {} features)", escaped_value)
} else if key == "target_feature" {
format!("(builtins.elem {} targetFeatures)", escaped_value)
} else {
format!("(target.{} == {})", target(key), escaped_value)
});
Expand Down Expand Up @@ -257,6 +259,13 @@ fn test_render_cfg_to_nix_expr() {
}

assert_eq!("target.\"unix\"", &cfg_to_nix_expr(&name("unix")));
assert_eq!(
"((builtins.elem \"aes\" targetFeatures) && (builtins.elem \"foo\" features))",
&cfg_to_nix_expr(&CfgExpr::All(vec![
kv("target_feature", "aes"),
kv("feature", "foo")
]))
);
assert_eq!(
"(target.\"os\" == \"linux\")",
&cfg_to_nix_expr(&kv("target_os", "linux"))
Expand Down
2 changes: 2 additions & 0 deletions crate2nix/templates/Cargo.nix.tera
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
, rootFeatures ? [ "default" ]
# If true, throw errors instead of issueing deprecation warnings.
, strictDeprecation ? false
# Used for conditional compilation based on CPU feature detection.
, targetFeatures ? []
# Whether to perform release builds: longer compile times, faster binaries.
, release ? true
# Additional crate2nix configuration if it exists.
Expand Down
2 changes: 2 additions & 0 deletions crate2nix/templates/nix/crate2nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
, strictDeprecation ? true
, crates ? { }
, rootFeatures ? [ ]
, targetFeatures ? [ ]
, release ? true
}:
rec {
Expand Down Expand Up @@ -311,6 +312,7 @@ rec {
crateConfig.sha256;
}
);
extraRustcOpts = lib.lists.optional (targetFeatures != [ ]) "-C target-feature=${stdenv.lib.concatMapStringsSep "," (x: "+${x}") targetFeatures}";
inherit features dependencies buildDependencies crateRenames release;
}
);
Expand Down
3 changes: 3 additions & 0 deletions sample_projects/bin_with_git_branch_dep/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
, rootFeatures ? [ "default" ]
# If true, throw errors instead of issueing deprecation warnings.
, strictDeprecation ? false
# Used for conditional compilation based on CPU feature detection.
, targetFeatures ? []
# Whether to perform release builds: longer compile times, faster binaries.
, release ? true
# Additional crate2nix configuration if it exists.
Expand Down Expand Up @@ -418,6 +420,7 @@ rec {
crateConfig.sha256;
}
);
extraRustcOpts = lib.lists.optional (targetFeatures != [ ]) "-C target-feature=${stdenv.lib.concatMapStringsSep "," (x: "+${x}") targetFeatures}";
inherit features dependencies buildDependencies crateRenames release;
}
);
Expand Down
3 changes: 3 additions & 0 deletions sample_projects/bin_with_git_submodule_dep/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
, rootFeatures ? [ "default" ]
# If true, throw errors instead of issueing deprecation warnings.
, strictDeprecation ? false
# Used for conditional compilation based on CPU feature detection.
, targetFeatures ? []
# Whether to perform release builds: longer compile times, faster binaries.
, release ? true
# Additional crate2nix configuration if it exists.
Expand Down Expand Up @@ -1591,6 +1593,7 @@ rec {
crateConfig.sha256;
}
);
extraRustcOpts = lib.lists.optional (targetFeatures != [ ]) "-C target-feature=${stdenv.lib.concatMapStringsSep "," (x: "+${x}") targetFeatures}";
inherit features dependencies buildDependencies crateRenames release;
}
);
Expand Down
3 changes: 3 additions & 0 deletions sample_projects/codegen/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
, rootFeatures ? [ "default" ]
# If true, throw errors instead of issueing deprecation warnings.
, strictDeprecation ? false
# Used for conditional compilation based on CPU feature detection.
, targetFeatures ? []
# Whether to perform release builds: longer compile times, faster binaries.
, release ? true
# Additional crate2nix configuration if it exists.
Expand Down Expand Up @@ -770,6 +772,7 @@ rec {
crateConfig.sha256;
}
);
extraRustcOpts = lib.lists.optional (targetFeatures != [ ]) "-C target-feature=${stdenv.lib.concatMapStringsSep "," (x: "+${x}") targetFeatures}";
inherit features dependencies buildDependencies crateRenames release;
}
);
Expand Down
3 changes: 3 additions & 0 deletions sample_projects/sub_dir_crates/Cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
, rootFeatures ? [ "default" ]
# If true, throw errors instead of issueing deprecation warnings.
, strictDeprecation ? false
# Used for conditional compilation based on CPU feature detection.
, targetFeatures ? []
# Whether to perform release builds: longer compile times, faster binaries.
, release ? true
# Additional crate2nix configuration if it exists.
Expand Down Expand Up @@ -437,6 +439,7 @@ rec {
crateConfig.sha256;
}
);
extraRustcOpts = lib.lists.optional (targetFeatures != [ ]) "-C target-feature=${stdenv.lib.concatMapStringsSep "," (x: "+${x}") targetFeatures}";
inherit features dependencies buildDependencies crateRenames release;
}
);
Expand Down