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 example with a non-workspace Cargo.toml #3019

Merged
merged 2 commits into from
Nov 24, 2024
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
14 changes: 7 additions & 7 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ tasks:
working_directory: examples/bzlmod/hello_world
test_flags: *bzlmod_flags
run_targets:
- "//third-party:vendor"
- "//third-party-in-workspace:vendor"
- "@rules_rust//tools/rust_analyzer:gen_rust_project"
test_targets:
- "//..."
Expand All @@ -735,7 +735,7 @@ tasks:
shell_commands:
- "rm MODULE.bazel.lock"
run_targets:
- "//third-party:vendor"
- "//third-party-in-workspace:vendor"
- "@rules_rust//tools/rust_analyzer:gen_rust_project"
test_targets:
- "//..."
Expand All @@ -745,7 +745,7 @@ tasks:
working_directory: examples/bzlmod/hello_world
test_flags: *bzlmod_flags
run_targets:
- "//third-party:vendor"
- "//third-party-in-workspace:vendor"
- "@rules_rust//tools/rust_analyzer:gen_rust_project"
test_targets:
- "//..."
Expand All @@ -756,7 +756,7 @@ tasks:
# working_directory: examples/bzlmod/hello_world
# test_flags: *bzlmod_flags
# run_targets:
# - "//third-party:vendor"
# - "//third-party-in-workspace:vendor"
# build_targets:
# - "@rules_rust//tools/rust_analyzer:gen_rust_project"
# test_targets:
Expand All @@ -770,7 +770,7 @@ tasks:
working_directory: examples/bzlmod/hello_world
test_flags: *bzlmod_plus_repo_names_flags
run_targets:
- "//third-party:vendor"
- "//third-party-in-workspace:vendor"
- "@rules_rust//tools/rust_analyzer:gen_rust_project"
test_targets:
- "//..."
Expand All @@ -783,7 +783,7 @@ tasks:
working_directory: examples/bzlmod/hello_world
test_flags: *bzlmod_plus_repo_names_flags
run_targets:
- "//third-party:vendor"
- "//third-party-in-workspace:vendor"
- "@rules_rust//tools/rust_analyzer:gen_rust_project"
test_targets:
- "//..."
Expand All @@ -796,7 +796,7 @@ tasks:
working_directory: examples/bzlmod/hello_world
test_flags: *bzlmod_plus_repo_names_flags
run_targets:
- "//third-party:vendor"
- "//third-party-in-workspace:vendor"
build_targets:
- "@rules_rust//tools/rust_analyzer:gen_rust_project"
test_targets:
Expand Down
4 changes: 2 additions & 2 deletions .bcr/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ bcr_test_module:
shell_commands:
- "rm MODULE.bazel.lock"
run_targets:
- "//third-party:vendor"
- "//third-party-in-workspace:vendor"
- "@rules_rust//tools/rust_analyzer:gen_rust_project"
test_targets:
- "//..."
Expand All @@ -32,7 +32,7 @@ bcr_test_module_windows:
shell_commands:
- "rm MODULE.bazel.lock"
run_targets:
- "//third-party:vendor"
- "//third-party-in-workspace:vendor"
build_targets:
- "@rules_rust//tools/rust_analyzer:gen_rust_project"
test_targets:
Expand Down
26 changes: 18 additions & 8 deletions examples/bzlmod/hello_world/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,26 @@ load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_doc")
package(default_visibility = ["//visibility:public"])

rust_binary(
name = "hello_world_transient",
name = "hello_world_from_workspace_transient",
srcs = ["src/main.rs"],
deps = [
"@crates//:anyhow",
"@crates_in_workspace//:anyhow",
],
)

rust_binary(
name = "hello_world_vendored",
name = "hello_world_from_workspace_vendored",
srcs = ["src/main.rs"],
deps = [
"//third-party/crates:anyhow",
"//third-party-in-workspace/crates:anyhow",
],
)

rust_binary(
name = "hello_world_without_workspace_transient",
srcs = ["src/main.rs"],
deps = [
"@crates_without_workspace//:anyhow",
],
)

Expand All @@ -25,8 +33,9 @@ rust_binary(
crate = ":hello_world_{}".format(target),
)
for target in [
"transient",
"vendored",
"from_workspace_transient",
"from_workspace_vendored",
"without_workspace_transient",
]
]

Expand All @@ -45,8 +54,9 @@ rust_binary(
],
)
for target in [
"transient",
"vendored",
"from_workspace_transient",
"from_workspace_vendored",
"without_workspace_transient",
]
]

Expand Down
23 changes: 17 additions & 6 deletions examples/bzlmod/hello_world/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,34 @@ crate = use_extension(
"crate",
)
crate.from_cargo(
name = "crates",
cargo_lockfile = "//third-party:Cargo.lock",
manifests = ["//third-party:Cargo.toml"],
name = "crates_in_workspace",
cargo_lockfile = "//third-party-in-workspace:Cargo.lock",
manifests = ["//third-party-in-workspace:Cargo.toml"],
)
use_repo(crate, "crates")
use_repo(crate, "crates_in_workspace")
crate.annotation(
additive_build_file = "//:BUILD.anyhow.bazel",
crate = "anyhow",
# Defined in additive_build_file.
data = [":cargo_toml"],
# Optional, you probably don't need this. Defaults to all from_cargo
# invocations in this module.
repositories = ["crates"],
repositories = [
"crates_in_workspace",
"crates_without_workspace",
],
# Optional, you probably don't need this, defaults to "*".
version = "*",
)

# Option 2: Vendored crates
crate_repositories = use_extension("//third-party:extension.bzl", "crate_repositories")
crate_repositories = use_extension("//third-party-in-workspace:extension.bzl", "crate_repositories")
use_repo(crate_repositories, "vendor__anyhow-1.0.77")

# Another example of Option 1, but where the Cargo.toml file isn't a [workspace]
crate.from_cargo(
name = "crates_without_workspace",
cargo_lockfile = "//third-party-without-workspace:Cargo.lock",
manifests = ["//third-party-without-workspace:Cargo.toml"],
)
use_repo(crate, "crates_without_workspace")
Loading
Loading