Skip to content

Commit

Permalink
Add example with a non-workspace Cargo.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
illicitonion committed Nov 24, 2024
1 parent c095694 commit ccacf8f
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 10 deletions.
28 changes: 19 additions & 9 deletions examples/bzlmod/hello_world/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,44 @@ rust_binary(
],
)

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

[
rust_doc(
name = "hello_world_from_workspace_{}_doc".format(target),
crate = ":hello_world_from_workspace_{}".format(target),
name = "hello_world_{}_doc".format(target),
crate = ":hello_world_{}".format(target),
)
for target in [
"transient",
"vendored",
"from_workspace_transient",
"from_workspace_vendored",
"without_workspace_transient",
]
]

[
sh_test(
name = "hello_world_from_workspace_{}_test".format(target),
name = "hello_world_{}_test".format(target),
srcs = ["hello_world_test.sh"],
args = [
"$(rlocationpath :hello_world_from_workspace_{})".format(target),
"$(rlocationpath :hello_world_{})".format(target),
],
data = [
":hello_world_from_workspace_{}".format(target),
":hello_world_{}".format(target),
],
deps = [
"@bazel_tools//tools/bash/runfiles",
],
)
for target in [
"transient",
"vendored",
"from_workspace_transient",
"from_workspace_vendored",
"without_workspace_transient",
]
]

Expand Down
10 changes: 9 additions & 1 deletion examples/bzlmod/hello_world/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,19 @@ crate.annotation(
data = [":cargo_toml"],
# Optional, you probably don't need this. Defaults to all from_cargo
# invocations in this module.
repositories = ["crates_in_workspace"],
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-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")
Empty file.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "third-party"
version = "0.0.0"
edition = "2021"
publish = false

[lib]
path = "fake.rs"

[dependencies]
anyhow = "1.0.77"

0 comments on commit ccacf8f

Please sign in to comment.