Skip to content

Commit

Permalink
Demo: Add override_rustc_flags
Browse files Browse the repository at this point in the history
This makes it possible to do platform specific flags, needed e.g. in
value-bag to compile both for WASM and non-WASM. Usage example:

[package.metadata.raze.crates.value-bag.'1.0.0-alpha.8']
gen_buildrs = false
override_rustc_flags = """
    [ "--cap-lints=allow" ] +
    selects.with_or({
        (
            "@rules_rust//rust/platform:wasm32-unknown-unknown",
        ): ["--cfg=value_bag_capture_fallback"],
        "//conditions:default": ["--cfg=value_bag_capture_ctor"],
    })
"""
  • Loading branch information
ttiurani committed Nov 12, 2021
1 parent a28427d commit 07c775b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion impl/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@rules_rust//rust:rust.bzl", "rust_binary", "rust_library", "rust_test")
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", "rust_test")
load("//third_party/cargo:crates.bzl", "all_crate_deps")

package(default_visibility = ["//visibility:public"])
Expand Down
6 changes: 5 additions & 1 deletion impl/src/rendering/templates/partials/common_attrs.template
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,18 @@
{%- endfor %}
},
{%- endif %}
{%- if crate.raze_settings.override_rustc_flags %}
rustc_flags = {{crate.raze_settings.override_rustc_flags}},
{%- else %}
rustc_flags = [
"--cap-lints=allow",
{%- for flag in crate.raze_settings.additional_flags %}
"{{flag}}",
{%- endfor %}
],
{%- endif %}
tags = [
"cargo-raze",
"manual",
],
version = "{{ crate.pkg_version }}",
version = "{{ crate.pkg_version }}",
5 changes: 5 additions & 0 deletions impl/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ pub struct CrateSettings {
#[serde(default)]
pub additional_flags: Vec<String>,

/// Escape hatch for override value for rustc_flags, make sure to include "--cap-lints=allow"
#[serde(default)]
pub override_rustc_flags: Option<String>,

/// Environment variables to be added to the crate compilation process.
#[serde(default)]
pub additional_env: BTreeMap<String, String>,
Expand Down Expand Up @@ -274,6 +278,7 @@ impl Default for CrateSettings {
build_data_dependencies: Vec::new(),
buildrs_additional_deps: Vec::new(),
buildrs_additional_environment_variables: BTreeMap::new(),
override_rustc_flags: None,
patch_args: Vec::new(),
patch_cmds: Vec::new(),
patch_cmds_win: Vec::new(),
Expand Down

0 comments on commit 07c775b

Please sign in to comment.