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

Accept [package.metadata.raze], superseding [raze] #274

Merged
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
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ path = "fake_lib.rs"
[dependencies]
log = "=0.3.6"

[raze]
[package.metadata.raze]
# The path relative path to the Bazel workspace root (location of
# WORKSPACE.bazel/WORKSPACE file). If no workspace file is found,
# the current working directory is used.
Expand Down Expand Up @@ -135,10 +135,10 @@ is required.
#### Generate a Cargo.toml

Generate a Cargo.toml, similar to Vendoring mode but add a new `genmode` directive in the
`[raze]` section
`[package.metadata.raze]` section

```toml
[raze]
[package.metadata.raze]
# The path relative path to the Bazel workspace root (location of
# WORKSPACE.bazel/WORKSPACE file). If no workspace file is found,
# the current working directory is used.
Expand Down Expand Up @@ -198,7 +198,7 @@ source file. These build-scripts rules can actually be executed and used within
Bazel by including a directive in your Cargo.toml prior to generation:

```toml
[raze.crates.clang-sys.'0.21.1']
[package.metadata.raze.crates.clang-sys.'0.21.1']
gen_buildrs = true
```

Expand All @@ -214,7 +214,7 @@ compilation target is statically known), they can be provided from within the
Cargo.toml, in the following manner

```toml
[raze.crates.unicase.'2.1.0']
[package.metadata.raze.crates.unicase.'2.1.0']
additional_flags = [
# Rustc is 1.15, enable all optional settings
"--cfg=__unicase__iter_cmp",
Expand All @@ -235,7 +235,7 @@ rule for it, and add the dependency to the corresponding `-sys` crate. For
openssl, this may in part look like:

```toml
[raze.crates.openssl-sys.'0.9.24']
[package.metadata.raze.crates.openssl-sys.'0.9.24']
additional_flags = [
# Vendored openssl is 1.0.2m
"--cfg=ossl102",
Expand All @@ -246,7 +246,7 @@ additional_deps = [
"@//third_party/openssl:ssl",
]

[raze.crates.openssl.'0.10.2']
[package.metadata.raze.crates.openssl.'0.10.2']
additional_flags = [
# Vendored openssl is 1.0.2m
"--cfg=ossl102",
Expand All @@ -273,7 +273,7 @@ facilitated by removing and supplementing dependencies in the Cargo.toml,
pre-generation:

```toml
[raze.crates.sdl2.'0.31.0']
[package.metadata.raze.crates.sdl2.'0.31.0']
skipped_deps = [
"sdl2-sys-0.31.0"
]
Expand All @@ -290,7 +290,7 @@ files by processing C or C++ files. A directive can be added to the Cargo.toml
to tell Bazel to expose such binaries for you:

```toml
[raze.crates.bindgen.'0.32.2']
[package.metadata.raze.crates.bindgen.'0.32.2']
gen_buildrs = true # needed to build bindgen
extra_aliased_targets = [
"cargo_bin_bindgen"
Expand All @@ -308,14 +308,14 @@ of your `Cargo.toml` file will not result in generated Bazel targets. Cargo-raze
has a special field to handle these crates when using `genmode = "Remote"`:

```toml
[raze.binary_deps]
[package.metadata.raze.binary_deps]
wasm-bindgen-cli = "0.2.68"
```

In the snippet above, the `wasm-bindgen-cli` crate is defined as binary dependency
and Cargo-raze will ensure metadata for this and any other crate defined here are
included in the resulting output directory. Lockfiles for targets specified under
`[raze.binary_deps]` will be generated into a `lockfiles` directory inside the path
`[package.metadata.raze.binary_deps]` will be generated into a `lockfiles` directory inside the path
specified by `workspace_path`.

## FAQ
Expand Down Expand Up @@ -394,4 +394,4 @@ See these examples of providing crate configuration:

- [openssl](https://github.com/acmcarther/compile_openssl)

The `[raze]` section is derived from a struct declared in [impl/src/settings.rs](./impl/src/settings.rs).
The `[package.metadata.raze]` section is derived from a struct declared in [impl/src/settings.rs](./impl/src/settings.rs).
2 changes: 1 addition & 1 deletion examples/remote/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ In order to make sure that this assertion holds, please make sure set up **Cargo
**Cargo.toml**
```toml

[raze]
[package.metadata.raze]
gen_workspace_prefix = "<folder>"
```
10 changes: 5 additions & 5 deletions examples/remote/binary_dependencies/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ path = "src/main.rs"
[dependencies]
ferris-says = "0.2.0"

[raze]
[package.metadata.raze]
workspace_path = "//remote/binary_dependencies/cargo"
gen_workspace_prefix = "remote_binary_dependencies"
genmode = "Remote"
default_gen_buildrs = true

[raze.binary_deps]
[package.metadata.raze.binary_deps]
texture-synthesis-cli = "0.8.0"

[raze.crates.texture-synthesis-cli.'0.8.0']
[package.metadata.raze.crates.texture-synthesis-cli.'0.8.0']
extra_aliased_targets = ["cargo_bin_texture_synthesis"]

[raze.crates.crossbeam-utils.'0.7.2']
[package.metadata.raze.crates.crossbeam-utils.'0.7.2']
gen_buildrs = false

[raze.crates.image.'0.23.0']
[package.metadata.raze.crates.image.'0.23.0']
data_attr = "[\"README.md\"]"
10 changes: 5 additions & 5 deletions examples/remote/complicated_cargo_library/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ regex = "=0.2.5"
specs = "=0.10.0"
security-framework-sys = "=0.2.2"

[raze]
[package.metadata.raze]
workspace_path = "//remote/complicated_cargo_library/cargo"
gen_workspace_prefix = "remote_complicated_cargo_library"
genmode = "Remote"

[raze.crates.proc-macro2.'0.4.30']
[package.metadata.raze.crates.proc-macro2.'0.4.30']
additional_flags = [
"--cfg=use_proc_macro",
]

[raze.crates.syn.'0.15.44']
[package.metadata.raze.crates.syn.'0.15.44']
gen_buildrs = true

[raze.crates.libloading.'0.5.2']
[package.metadata.raze.crates.libloading.'0.5.2']
additional_deps = [":global_static"]
additional_build_file = "cargo/libloading_global_static.BUILD"

[raze.crates.regex.'0.2.5']
[package.metadata.raze.crates.regex.'0.2.5']
skipped_deps = [
# This will break the regex crate
#"regex-syntax-0.4.2"
Expand Down
2 changes: 1 addition & 1 deletion examples/remote/no_deps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = ["UebelAndre <github@uebelandre.com>"]
name = "no_deps"
path = "src/main.rs"

[raze]
[package.metadata.raze]
workspace_path = "//remote/no_deps/cargo"
genmode = "Remote"
gen_workspace_prefix = "remote_no_deps"
4 changes: 2 additions & 2 deletions examples/remote/non_cratesio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ log = { git = "https://github.com/rust-lang-nursery/log.git", rev = "bf40d1f563c
name = "non_cratesio"
path = "src/main.rs"

[raze]
[package.metadata.raze]
workspace_path = "//remote/non_cratesio/cargo"
target = "x86_64-unknown-linux-gnu"
genmode = "Remote"
gen_workspace_prefix = "remote_non_cratesio"

[raze.crates.log.'0.4.11']
[package.metadata.raze.crates.log.'0.4.11']
additional_flags = [
"--cfg=atomic_cas"
]
2 changes: 1 addition & 1 deletion examples/remote/non_cratesio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

1. Run `cargo install cargo-raze`
2. Generate a Cargo.toml with desired dependencies into cargo/Cargo.toml
3. Add a [raze] section with your desired options (see cargo-raze `settings::CargoToml` for
3. Add a [package.metadata.raze] section with your desired options (see cargo-raze `settings::CargoToml` for
the exact details)
4. Run `cargo vendor --versioned-dirs` from `cargo/`
5. Run `cargo raze` from `cargo/`
Expand Down
8 changes: 4 additions & 4 deletions examples/vendored/complicated_cargo_library/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ specs = "0.10.0"
name = "complicated_cargo_library"
path = "src/main.rs"

[raze]
[package.metadata.raze]
workspace_path = "//vendored/complicated_cargo_library/cargo"
gen_workspace_prefix = "vendored_complicated_cargo_library"
genmode = "Vendored"

[raze.crates.proc-macro2.'0.4.30']
[package.metadata.raze.crates.proc-macro2.'0.4.30']
additional_flags = [
"--cfg=use_proc_macro",
]

[raze.crates.regex.'0.2.11']
[package.metadata.raze.crates.regex.'0.2.11']
additional_deps = [
# Add an unused dep
"//vendored/complicated_cargo_library/cargo:specs"
Expand All @@ -34,5 +34,5 @@ additional_flags = [
# Add an unused environment variable
additional_env = { NOT_USED_KEY = "not_used_value" }

[raze.crates.conduit-mime-types.'0.7.3']
[package.metadata.raze.crates.conduit-mime-types.'0.7.3']
data_attr = "glob([\"data/**\"])"
2 changes: 1 addition & 1 deletion examples/vendored/hello_cargo_library/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fern = "=0.3.5"
name = "hello_cargo_library"
path = "src/main.rs"

[raze]
[package.metadata.raze]
workspace_path = "//vendored/hello_cargo_library/cargo"
target = "x86_64-unknown-linux-gnu"
output_buildfile_suffix = "BUILD.bazel"
Expand Down
4 changes: 2 additions & 2 deletions examples/vendored/non_cratesio_library/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ log = { git = "https://github.com/rust-lang-nursery/log.git", rev = "bf40d1f563c
name = "non_cratesio_library"
path = "src/main.rs"

[raze]
[package.metadata.raze]
workspace_path = "//vendored/non_cratesio_library/cargo"
target = "x86_64-unknown-linux-gnu"
gen_workspace_prefix = "vendored_non_cratesio_library"
genmode = "Vendored"

[raze.crates.log.'0.4.11']
[package.metadata.raze.crates.log.'0.4.11']
additional_flags = [
"--cfg=atomic_cas"
]
43 changes: 41 additions & 2 deletions impl/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,18 @@ pub type CrateSettingsPerVersion = HashMap<Version, CrateSettings>;
*/
#[derive(Debug, Clone, Deserialize)]
pub struct CargoToml {
pub raze: RazeSettings,
pub raze: Option<RazeSettings>,
pub package: Option<PackageToml>,
}

#[derive(Debug, Clone, Deserialize)]
pub struct PackageToml {
pub metadata: Option<MetadataToml>,
}

#[derive(Debug, Clone, Deserialize)]
pub struct MetadataToml {
pub raze: Option<RazeSettings>,
}

/** The configuration settings for `cargo-raze`, included in Cargo.toml. */
Expand Down Expand Up @@ -370,7 +381,35 @@ pub fn load_settings<T: AsRef<Path>>(cargo_toml_path: T) -> Result<RazeSettings,
return Err(RazeError::Generic(err.to_string()));
}
let mut settings = match toml::from_str::<CargoToml>(&toml_contents) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know if package.metadata.raze settings can be parsed from cargo metadata?

Specifically, could something like the CargoMetadataFetcher be used to load these settings more holistically?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, they can. It looks like this:

$ cargo metadata --format-version 1 | jq '.. | .raze? | select(.)'
{
  "genmode": "Remote",
  "workspace_path": "//third_party/rust",
  "crates": {
    "crc": {
      "1.8.1": {
        "gen_buildrs": true
      }
    },
    "indexmap": {
      "1.6.0": {
        "additional_flags": [
          "--cfg=has_std"
        ]
      }
    },
    "proc-macro2": {
      "1.0.24": {
        "additional_flags": [
          "--cfg=use_proc_macro",
          "--cfg=wrap_proc_macro"
        ]
      }
    },
    "prost-build": {
      "0.6.1": {
        "gen_buildrs": true
      }
    },
    "thiserror": {
      "1.0.21": {
        "gen_buildrs": true
      }
    }
  }
}

The path is .packages[].metadata.raze, so you’d have to pluck it from
the right package.

I haven’t looked at CargoMetadataFetcher. If you’d prefer that
approach, I can do so (but no promises on when I’ll get around to it).

Note that [raze] does not show up in cargo metadata, so as long as
you want to keep both around you would need two parsing paths. So
I might propose a plan of (a) parse both from Cargo.toml, (b) wait
until comfortable dropping compat, (c) remove CargoToml::raze,
(d) migrate to parsing from cargo metadata now that that’s easier.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was more trying to find out if this information could be parsed all from cargo metadata.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the [package.metadata.raze] info can; the [raze] info can’t.

Ok(toml) => toml.raze,
Ok(CargoToml {
package:
Some(PackageToml {
metadata: Some(MetadataToml { raze: Some(raze) }),
}),
raze: top_level_raze,
}) => {
if top_level_raze.is_some() {
eprintln!(
"WARNING: Both [raze] and [package.metadata.raze] are set. \
Using [package.metadata.raze] and ignoring [raze], which is deprecated."
);
}
raze
},
Ok(CargoToml {
raze: Some(raze), ..
}) => {
eprintln!(
"WARNING: The top-level [raze] key is deprecated. \
Please set [package.metadata.raze] instead."
);
raze
},
Ok(_) => {
return Err(RazeError::Generic(
"Cargo.toml has no `raze` or `package.metadata.raze` field".into(),
));
},
Err(err) => {
return Err(RazeError::Generic(err.to_string()));
},
Expand Down
2 changes: 1 addition & 1 deletion smoke_test/remote/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ In order to make sure that this assertion holds, please make sure set up **Cargo
**Cargo.toml**
```toml

[raze]
[package.metadata.raze]
gen_workspace_prefix = "<folder>"
```
10 changes: 5 additions & 5 deletions smoke_test/remote/binary_dependencies/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ path = "src/main.rs"
[dependencies]
ferris-says = "0.2.0"

[raze]
[package.metadata.raze]
workspace_path = "//remote/binary_dependencies/cargo"
gen_workspace_prefix = "remote_binary_dependencies"
genmode = "Remote"
default_gen_buildrs = true

[raze.binary_deps]
[package.metadata.raze.binary_deps]
texture-synthesis-cli = "0.8.0"

[raze.crates.texture-synthesis-cli.'0.8.0']
[package.metadata.raze.crates.texture-synthesis-cli.'0.8.0']
extra_aliased_targets = ["cargo_bin_texture_synthesis"]

[raze.crates.crossbeam-utils.'0.7.2']
[package.metadata.raze.crates.crossbeam-utils.'0.7.2']
gen_buildrs = false

[raze.crates.image.'0.23.0']
[package.metadata.raze.crates.image.'0.23.0']
data_attr = "[\"README.md\"]"
10 changes: 5 additions & 5 deletions smoke_test/remote/complicated_cargo_library/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ regex = "=0.2.5"
specs = "=0.10.0"
security-framework-sys = "=0.2.2"

[raze]
[package.metadata.raze]
workspace_path = "//remote/complicated_cargo_library/cargo"
gen_workspace_prefix = "remote_complicated_cargo_library"
genmode = "Remote"

[raze.crates.proc-macro2.'0.4.30']
[package.metadata.raze.crates.proc-macro2.'0.4.30']
additional_flags = [
"--cfg=use_proc_macro",
]

[raze.crates.syn.'0.15.44']
[package.metadata.raze.crates.syn.'0.15.44']
gen_buildrs = true

[raze.crates.libloading.'0.5.2']
[package.metadata.raze.crates.libloading.'0.5.2']
additional_deps = [":global_static"]
additional_build_file = "cargo/libloading_global_static.BUILD"

[raze.crates.regex.'0.2.5']
[package.metadata.raze.crates.regex.'0.2.5']
skipped_deps = [
# This will break the regex crate
#"regex-syntax-0.4.2"
Expand Down
2 changes: 1 addition & 1 deletion smoke_test/remote/no_deps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = ["UebelAndre <github@uebelandre.com>"]
name = "no_deps"
path = "src/main.rs"

[raze]
[package.metadata.raze]
workspace_path = "//remote/no_deps/cargo"
genmode = "Remote"
gen_workspace_prefix = "remote_no_deps"
4 changes: 2 additions & 2 deletions smoke_test/remote/non_cratesio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ log = { git = "https://github.com/rust-lang-nursery/log.git", rev = "bf40d1f563c
name = "non_cratesio"
path = "src/main.rs"

[raze]
[package.metadata.raze]
workspace_path = "//remote/non_cratesio/cargo"
target = "x86_64-unknown-linux-gnu"
genmode = "Remote"
gen_workspace_prefix = "remote_non_cratesio"

[raze.crates.log.'0.4.11']
[package.metadata.raze.crates.log.'0.4.11']
additional_flags = [
"--cfg=atomic_cas"
]
Loading