Skip to content

Commit

Permalink
[cargo-gnaw] Tweak tests to fix cargo roll
Browse files Browse the repository at this point in the history
In rust-lang/cargo#10243, cargo was changed to
disallow crate-types that produce the same filename. This can happen
with `lib` and `rlib`, or `dylib` and `cdylib`. This changes the
`multiple_crate_type` to split out these into multiple sub-crates.

Note that because cargo-gnaw currently only supports generating rules
for `lib` types, we don't produce anything for the
`sub-crate-with-rlib`.

Change-Id: Id1c15e884de228f9024a6df1fc315e03a4a33bb4
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/637408
Fuchsia-Auto-Submit: Erick Tryzelaar <etryzelaar@google.com>
Reviewed-by: Adam Perry <adamperry@google.com>
Commit-Queue: Auto-Submit <auto-submit@fuchsia-infra.iam.gserviceaccount.com>
  • Loading branch information
erickt authored and Commit Bot committed Jan 25, 2022
1 parent 079c48d commit dc3c82b
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 16 deletions.
8 changes: 6 additions & 2 deletions tools/cargo-gnaw/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ if (is_host) {
"multiple_crate_types/Cargo.lock",
"multiple_crate_types/Cargo.toml",
"multiple_crate_types/src/lib.rs",
"multiple_crate_types/sub-crate/Cargo.toml",
"multiple_crate_types/sub-crate/src/lib.rs",
"multiple_crate_types/sub-crate-with-cdylib/Cargo.toml",
"multiple_crate_types/sub-crate-with-cdylib/src/lib.rs",
"multiple_crate_types/sub-crate-with-dylib/Cargo.toml",
"multiple_crate_types/sub-crate-with-dylib/src/lib.rs",
"multiple_crate_types/sub-crate-with-rlib/Cargo.toml",
"multiple_crate_types/sub-crate-with-rlib/src/lib.rs",
"platform_deps/.cargo/config",
"platform_deps/BUILD.gn",
"platform_deps/Cargo.lock",
Expand Down
37 changes: 30 additions & 7 deletions tools/cargo-gnaw/tests/multiple_crate_types/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ rust_library("multiple_crate_types-v1_0_25") {
output_name = "multiple_crate_types-8be5e59704cbf5a4"

deps = []
deps += [ ":sub-crate-v1_0_25" ]
deps += [ ":sub-crate-with-cdylib-v1_0_25" ]
deps += [ ":sub-crate-with-dylib-v1_0_25" ]
deps += [ ":sub-crate-with-rlib-v1_0_25" ]

rustenv = []

Expand All @@ -28,10 +30,10 @@ rust_library("multiple_crate_types-v1_0_25") {
visibility = [ ":*" ]
}

rust_library("sub-crate-v1_0_25") {
crate_name = "sub_crate"
crate_root = "//multiple_crate_types/sub-crate/src/lib.rs"
output_name = "sub_crate-c933a0443c39195"
rust_library("sub-crate-with-cdylib-v1_0_25") {
crate_name = "sub_crate_with_cdylib"
crate_root = "//multiple_crate_types/sub-crate-with-cdylib/src/lib.rs"
output_name = "sub_crate_with_cdylib-2c19a9098651391d"

deps = []

Expand All @@ -40,8 +42,29 @@ rust_library("sub-crate-v1_0_25") {
rustflags = [
"--cap-lints=allow",
"--edition=2018",
"-Cmetadata=c933a0443c39195",
"-Cextra-filename=-c933a0443c39195",
"-Cmetadata=2c19a9098651391d",
"-Cextra-filename=-2c19a9098651391d",
]

visibility = []
visibility += [ ":*" ]
visibility += [ "//foo/bar/*" ]
}

rust_library("sub-crate-with-dylib-v1_0_25") {
crate_name = "sub_crate_with_dylib"
crate_root = "//multiple_crate_types/sub-crate-with-dylib/src/lib.rs"
output_name = "sub_crate_with_dylib-cba782ed0389a004"

deps = []

rustenv = []

rustflags = [
"--cap-lints=allow",
"--edition=2018",
"-Cmetadata=cba782ed0389a004",
"-Cextra-filename=-cba782ed0389a004",
]

visibility = []
Expand Down
14 changes: 12 additions & 2 deletions tools/cargo-gnaw/tests/multiple_crate_types/Cargo.lock

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

9 changes: 7 additions & 2 deletions tools/cargo-gnaw/tests/multiple_crate_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ authors = ["Erick Tryzelaar <etryzelaar@google.com>"]
edition = "2018"

[dependencies]
sub-crate = { version = "1.0.25", path = "sub-crate" }
sub-crate-with-cdylib = { version = "1.0.25", path = "sub-crate-with-cdylib" }
sub-crate-with-dylib = { version = "1.0.25", path = "sub-crate-with-dylib" }
sub-crate-with-rlib = { version = "1.0.25", path = "sub-crate-with-rlib" }

[gn.package.sub-crate."1.0.25"]
[gn.package.sub-crate-with-cdylib."1.0.25"]
visibility = [":*", "//foo/bar/*"]

[gn.package.sub-crate-with-dylib."1.0.25"]
visibility = [":*", "//foo/bar/*"]
2 changes: 1 addition & 1 deletion tools/cargo-gnaw/tests/multiple_crate_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

fn some_fn() {
pub fn some_fn() {
println!("Hello, world!");
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "sub-crate"
name = "sub-crate-with-cdylib"
version = "1.0.25"
authors = ["Erick Tryzelaar <etryzelaar@google.com>"]
edition = "2018"

[lib]
crate-type = ["lib", "rlib", "staticlib", "dylib", "cdylib"]
crate-type = ["cdylib", "lib", "staticlib"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "sub-crate-with-dylib"
version = "1.0.25"
authors = ["Erick Tryzelaar <etryzelaar@google.com>"]
edition = "2018"

[lib]
crate-type = ["dylib", "lib", "staticlib"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright 2020 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// no-op
// hello there
pub const EXPORTED: u32 = 777;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "sub-crate-with-rlib"
version = "1.0.25"
authors = ["Erick Tryzelaar <etryzelaar@google.com>"]
edition = "2018"

[lib]
crate-type = ["rlib", "staticlib"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright 2020 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// no-op
// hello there
pub const EXPORTED: u32 = 777;

0 comments on commit dc3c82b

Please sign in to comment.