Skip to content

Commit

Permalink
Move examples into their own workspaces
Browse files Browse the repository at this point in the history
This is more clear, as they don't need to round-trip via two .bzl files,
so the examples are self-contained. However, we'll need to work out how
to make them build on CI.
  • Loading branch information
illicitonion committed Mar 3, 2021
1 parent 3a00856 commit 299f4e9
Show file tree
Hide file tree
Showing 14 changed files with 178 additions and 110 deletions.
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
docs
examples
examples/crate_universe
examples/cargo_manifest_dir/external_crate
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# bazel
/bazel-*
/examples/bazel-*
/examples/*/bazel-*
/examples/crate_universe/*/bazel-*
/docs/bazel-*

# rustfmt
Expand Down
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ examples_repositories()

load("@examples//:examples_deps.bzl", examples_deps = "deps")

examples_deps(is_top_level = True)
examples_deps()

load("@examples//:examples_transitive_deps.bzl", examples_transitive_deps = "transitive_deps")

Expand Down
2 changes: 1 addition & 1 deletion examples/crate_universe/basic/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ load(
"@rules_rust//rust:rust.bzl",
"rust_binary",
)
load("@crate_universe_basic_rust_deps//:defs.bzl", "crate")
load("@rust_deps//:defs.bzl", "crate")

rust_binary(
name = "basic",
Expand Down
32 changes: 32 additions & 0 deletions examples/crate_universe/basic/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
local_repository(
name = "rules_rust",
path = "../../..",
)

load("@rules_rust//rust:repositories.bzl", "rust_repositories")

rust_repositories()

load("@rules_rust//cargo:repositories.bzl", "crate_universe_deps")

crate_universe_deps()

load("@rules_rust//cargo:workspace.bzl", "crate", "crate_universe")

crate_universe(
name = "rust_deps",
packages = [
crate.spec(
name = "lazy_static",
semver = "=1.4",
),
],
supported_targets = [
"x86_64-apple-darwin",
"x86_64-unknown-linux-gnu",
],
)

load("@rust_deps//:defs.bzl", "pinned_rust_install")

pinned_rust_install()
2 changes: 1 addition & 1 deletion examples/crate_universe/has_aliased_deps/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ load(
"@rules_rust//rust:rust.bzl",
"rust_binary",
)
load("@crate_universe_has_aliased_deps_rust_deps//:defs.bzl", "crate")
load("@rust_deps//:defs.bzl", "crate")

rust_binary(
name = "has_aliased_deps",
Expand Down
55 changes: 55 additions & 0 deletions examples/crate_universe/has_aliased_deps/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
local_repository(
name = "rules_rust",
path = "../../..",
)

local_repository(
name = "examples",
path = "../../../examples",
)

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "openssl",
strip_prefix = "openssl-OpenSSL_1_1_1d",
urls = ["https://github.com/openssl/openssl/archive/OpenSSL_1_1_1d.tar.gz"],
sha256 = "23011a5cc78e53d0dc98dfa608c51e72bcd350aa57df74c5d5574ba4ffb62e74",
build_file = "@examples//third_party/openssl:BUILD.openssl.bazel",
)

load("@rules_rust//rust:repositories.bzl", "rust_repositories")

rust_repositories()

load("@rules_rust//cargo:repositories.bzl", "crate_universe_deps")

crate_universe_deps()

load("@rules_rust//cargo:workspace.bzl", "crate", "crate_universe")

crate_universe(
name = "rust_deps",
cargo_toml_files = ["//:Cargo.toml"],
overrides = {
"openssl-sys": crate.override(
extra_build_script_env_vars = {
"OPENSSL_DIR": "../openssl/openssl",
},
extra_bazel_deps = {
"cfg(all())": ["@openssl//:openssl"],
},
extra_build_script_bazel_data_deps = {
"cfg(all())": ["@openssl//:openssl"],
},
),
},
supported_targets = [
"x86_64-apple-darwin",
"x86_64-unknown-linux-gnu",
],
)

load("@rust_deps//:defs.bzl", "pinned_rust_install")

pinned_rust_install()
2 changes: 1 addition & 1 deletion examples/crate_universe/uses_proc_macro/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ load(
"rust_binary",
)

load("@crate_universe_uses_proc_macro_rust_deps//:defs.bzl", "crate")
load("@rust_deps//:defs.bzl", "crate")

rust_binary(
name = "uses_proc_macro",
Expand Down
27 changes: 27 additions & 0 deletions examples/crate_universe/uses_proc_macro/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
local_repository(
name = "rules_rust",
path = "../../..",
)

load("@rules_rust//rust:repositories.bzl", "rust_repositories")

rust_repositories()

load("@rules_rust//cargo:repositories.bzl", "crate_universe_deps")

crate_universe_deps()

load("@rules_rust//cargo:workspace.bzl", "crate", "crate_universe")

crate_universe(
name = "rust_deps",
cargo_toml_files = ["//:Cargo.toml"],
supported_targets = [
"x86_64-apple-darwin",
"x86_64-unknown-linux-gnu",
],
)

load("@rust_deps//:defs.bzl", "pinned_rust_install")

pinned_rust_install()
2 changes: 1 addition & 1 deletion examples/crate_universe/uses_sys_crate/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ load(
"@rules_rust//rust:rust.bzl",
"rust_binary",
)
load("@crate_universe_uses_sys_crate_rust_deps//:defs.bzl", "crate")
load("@rust_deps//:defs.bzl", "crate")

rust_binary(
name = "uses_sys_crate",
Expand Down
34 changes: 34 additions & 0 deletions examples/crate_universe/uses_sys_crate/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
local_repository(
name = "rules_rust",
path = "../../..",
)

load("@rules_rust//rust:repositories.bzl", "rust_repositories")

rust_repositories()

load("@rules_rust//cargo:repositories.bzl", "crate_universe_deps")

crate_universe_deps()

load("@rules_rust//cargo:workspace.bzl", "crate", "crate_universe")

crate_universe(
name = "rust_deps",
cargo_toml_files = ["//:Cargo.toml"],
lockfile = "//:lockfile.lock",
packages = [
crate.spec(
name = "libc",
semver = "=0.2.76",
),
],
supported_targets = [
"x86_64-apple-darwin",
"x86_64-unknown-linux-gnu",
],
)

load("@rust_deps//:defs.bzl", "pinned_rust_install")

pinned_rust_install()
44 changes: 22 additions & 22 deletions examples/crate_universe/uses_sys_crate/lockfile.lock
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# rules_rust crate_universe file format 1
# config hash d555ad6fce4572c24cb874f784ca32c0b4c5c6b6655c759f6b1381c0ef72667a
# config hash 6194c33fc29701bfce95fa6d31095bf1268a7ae6aab060692153d2e9fcd34373

load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

def pinned_rust_install():
http_archive(
name = "crate_universe_uses_sys_crate_rust_deps__bzip2__0_3_3",
name = "rust_deps__bzip2__0_3_3",
# TODO: Allow configuring where rust_library comes from
build_file_content = """# buildifier: disable=load
load(
Expand Down Expand Up @@ -35,8 +35,8 @@ rust_library(
name = "bzip2",
crate_type = "lib",
deps = [
"@crate_universe_uses_sys_crate_rust_deps__bzip2_sys__0_1_10_1_0_8//:bzip2_sys",
"@crate_universe_uses_sys_crate_rust_deps__libc__0_2_76//:libc",
"@rust_deps__bzip2_sys__0_1_10_1_0_8//:bzip2_sys",
"@rust_deps__libc__0_2_76//:libc",
],
srcs = glob(["**/*.rs"]),
crate_root = "src/lib.rs",
Expand Down Expand Up @@ -78,7 +78,7 @@ rust_library(
)

http_archive(
name = "crate_universe_uses_sys_crate_rust_deps__bzip2_sys__0_1_10_1_0_8",
name = "rust_deps__bzip2_sys__0_1_10_1_0_8",
# TODO: Allow configuring where rust_library comes from
build_file_content = """# buildifier: disable=load
load(
Expand Down Expand Up @@ -113,8 +113,8 @@ cargo_build_script(
crate_root = "build.rs",
edition = "2015",
deps = [
"@crate_universe_uses_sys_crate_rust_deps__cc__1_0_66//:cc",
"@crate_universe_uses_sys_crate_rust_deps__pkg_config__0_3_19//:pkg_config",
"@rust_deps__cc__1_0_67//:cc",
"@rust_deps__pkg_config__0_3_19//:pkg_config",
],
rustc_flags = [
"--cap-lints=allow",
Expand Down Expand Up @@ -151,7 +151,7 @@ rust_library(
crate_type = "lib",
deps = [
":bzip2_sys_build_script",
"@crate_universe_uses_sys_crate_rust_deps__libc__0_2_76//:libc",
"@rust_deps__libc__0_2_76//:libc",
],
srcs = glob(["**/*.rs"]),
crate_root = "lib.rs",
Expand Down Expand Up @@ -192,7 +192,7 @@ rust_library(
)

http_archive(
name = "crate_universe_uses_sys_crate_rust_deps__cc__1_0_66",
name = "rust_deps__cc__1_0_67",
# TODO: Allow configuring where rust_library comes from
build_file_content = """# buildifier: disable=load
load(
Expand Down Expand Up @@ -242,7 +242,7 @@ rust_binary(
"WORKSPACE.bazel",
"WORKSPACE",
]),
version = "1.0.66",
version = "1.0.67",
tags = [
"cargo-raze",
"manual",
Expand Down Expand Up @@ -280,7 +280,7 @@ rust_library(
"WORKSPACE.bazel",
"WORKSPACE",
]),
version = "1.0.66",
version = "1.0.67",
tags = [
"cargo-raze",
"manual",
Expand All @@ -298,14 +298,14 @@ rust_library(
# Unsupported target "cxxflags" with type "test" omitted
# Unsupported target "test" with type "test" omitted
""",
sha256 = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48",
strip_prefix = "cc-1.0.66",
sha256 = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd",
strip_prefix = "cc-1.0.67",
type = "tar.gz",
url = "https://crates.io/api/v1/crates/cc/1.0.66/download",
url = "https://crates.io/api/v1/crates/cc/1.0.67/download",
)

http_archive(
name = "crate_universe_uses_sys_crate_rust_deps__libc__0_2_76",
name = "rust_deps__libc__0_2_76",
# TODO: Allow configuring where rust_library comes from
build_file_content = """# buildifier: disable=load
load(
Expand Down Expand Up @@ -420,7 +420,7 @@ rust_library(
)

http_archive(
name = "crate_universe_uses_sys_crate_rust_deps__pkg_config__0_3_19",
name = "rust_deps__pkg_config__0_3_19",
# TODO: Allow configuring where rust_library comes from
build_file_content = """# buildifier: disable=load
load(
Expand Down Expand Up @@ -490,8 +490,8 @@ rust_library(


CRATE_TARGET_NAMES = {
"bzip2": "@crate_universe_uses_sys_crate_rust_deps__bzip2__0_3_3//:bzip2",
"libc": "@crate_universe_uses_sys_crate_rust_deps__libc__0_2_76//:libc",
"bzip2": "@rust_deps__bzip2__0_3_3//:bzip2",
"libc": "@rust_deps__libc__0_2_76//:libc",
}

def crate(crate_name):
Expand Down Expand Up @@ -520,25 +520,25 @@ def all_proc_macro_deps():

def crates_from(label):
mapping = {
"@examples//crate_universe/uses_sys_crate:Cargo.toml": [crate("bzip2")],
"//:Cargo.toml": [crate("bzip2")],
}
return mapping[_absolutify(label)]

def dev_crates_from(label):
mapping = {
"@examples//crate_universe/uses_sys_crate:Cargo.toml": [],
"//:Cargo.toml": [],
}
return mapping[_absolutify(label)]

def build_crates_from(label):
mapping = {
"@examples//crate_universe/uses_sys_crate:Cargo.toml": [],
"//:Cargo.toml": [],
}
return mapping[_absolutify(label)]

def proc_macro_crates_from(label):
mapping = {
"@examples//crate_universe/uses_sys_crate:Cargo.toml": [],
"//:Cargo.toml": [],
}
return mapping[_absolutify(label)]

Expand Down
Loading

0 comments on commit 299f4e9

Please sign in to comment.