diff --git a/.bazelignore b/.bazelignore index 1617deec04..0cb7ed8515 100644 --- a/.bazelignore +++ b/.bazelignore @@ -1,3 +1,4 @@ docs examples +examples/crate_universe examples/cargo_manifest_dir/external_crate diff --git a/.gitignore b/.gitignore index 17f523dc1a..38926597df 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,7 @@ # bazel /bazel-* /examples/bazel-* -/examples/*/bazel-* +/examples/crate_universe/*/bazel-* /docs/bazel-* # rustfmt diff --git a/WORKSPACE b/WORKSPACE index 23c8bb9cac..67c7f5117c 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -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") diff --git a/examples/crate_universe/basic/BUILD.bazel b/examples/crate_universe/basic/BUILD.bazel index 09ec6c8223..8ea6186f46 100644 --- a/examples/crate_universe/basic/BUILD.bazel +++ b/examples/crate_universe/basic/BUILD.bazel @@ -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", diff --git a/examples/crate_universe/basic/WORKSPACE b/examples/crate_universe/basic/WORKSPACE new file mode 100644 index 0000000000..5e2c45e147 --- /dev/null +++ b/examples/crate_universe/basic/WORKSPACE @@ -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() diff --git a/examples/crate_universe/has_aliased_deps/BUILD.bazel b/examples/crate_universe/has_aliased_deps/BUILD.bazel index 65817354fe..62bd68681c 100644 --- a/examples/crate_universe/has_aliased_deps/BUILD.bazel +++ b/examples/crate_universe/has_aliased_deps/BUILD.bazel @@ -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", diff --git a/examples/crate_universe/has_aliased_deps/WORKSPACE b/examples/crate_universe/has_aliased_deps/WORKSPACE new file mode 100644 index 0000000000..fcb8259a9f --- /dev/null +++ b/examples/crate_universe/has_aliased_deps/WORKSPACE @@ -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() diff --git a/examples/crate_universe/uses_proc_macro/BUILD.bazel b/examples/crate_universe/uses_proc_macro/BUILD.bazel index ffd022877d..437f31703b 100644 --- a/examples/crate_universe/uses_proc_macro/BUILD.bazel +++ b/examples/crate_universe/uses_proc_macro/BUILD.bazel @@ -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", diff --git a/examples/crate_universe/uses_proc_macro/WORKSPACE b/examples/crate_universe/uses_proc_macro/WORKSPACE new file mode 100644 index 0000000000..5eff654cde --- /dev/null +++ b/examples/crate_universe/uses_proc_macro/WORKSPACE @@ -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() diff --git a/examples/crate_universe/uses_sys_crate/BUILD.bazel b/examples/crate_universe/uses_sys_crate/BUILD.bazel index 5c7a0c11e2..68b28af46e 100644 --- a/examples/crate_universe/uses_sys_crate/BUILD.bazel +++ b/examples/crate_universe/uses_sys_crate/BUILD.bazel @@ -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", diff --git a/examples/crate_universe/uses_sys_crate/WORKSPACE b/examples/crate_universe/uses_sys_crate/WORKSPACE new file mode 100644 index 0000000000..49030bfb91 --- /dev/null +++ b/examples/crate_universe/uses_sys_crate/WORKSPACE @@ -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() diff --git a/examples/crate_universe/uses_sys_crate/lockfile.lock b/examples/crate_universe/uses_sys_crate/lockfile.lock index f6d25611c6..ca3d2988da 100644 --- a/examples/crate_universe/uses_sys_crate/lockfile.lock +++ b/examples/crate_universe/uses_sys_crate/lockfile.lock @@ -1,5 +1,5 @@ # 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") @@ -7,7 +7,7 @@ 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( @@ -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", @@ -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( @@ -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", @@ -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", @@ -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( @@ -242,7 +242,7 @@ rust_binary( "WORKSPACE.bazel", "WORKSPACE", ]), - version = "1.0.66", + version = "1.0.67", tags = [ "cargo-raze", "manual", @@ -280,7 +280,7 @@ rust_library( "WORKSPACE.bazel", "WORKSPACE", ]), - version = "1.0.66", + version = "1.0.67", tags = [ "cargo-raze", "manual", @@ -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( @@ -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( @@ -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): @@ -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)] diff --git a/examples/examples_deps.bzl b/examples/examples_deps.bzl index 5c163c9973..c669cca615 100644 --- a/examples/examples_deps.bzl +++ b/examples/examples_deps.bzl @@ -9,15 +9,10 @@ load("@rules_rust//bindgen:repositories.bzl", "rust_bindgen_repositories") load("@rules_rust//proto:repositories.bzl", "rust_proto_repositories") load("@rules_rust//rust:repositories.bzl", "rust_repositories", "rust_repository_set") load("@rules_rust//wasm_bindgen:repositories.bzl", "rust_wasm_bindgen_repositories") -load("@rules_rust//cargo:repositories.bzl", "crate_universe_deps") -load("@rules_rust//cargo:workspace.bzl", "crate", "crate_universe") - -def deps(is_top_level = False): +def deps(): """Define dependencies for `rules_rust` examples""" - examples_prefix = "@examples" if is_top_level else "" - rust_repositories() rust_bindgen_repositories() @@ -58,66 +53,3 @@ def deps(is_top_level = False): ) rules_foreign_cc_dependencies() - - crate_universe_deps() - - crate_universe( - name = "crate_universe_basic_rust_deps", - packages = [ - crate.spec( - name = "lazy_static", - semver = "=1.4", - ), - ], - supported_targets = [ - "x86_64-apple-darwin", - "x86_64-unknown-linux-gnu", - ], - ) - - crate_universe( - name = "crate_universe_uses_proc_macro_rust_deps", - cargo_toml_files = [examples_prefix + "//crate_universe/uses_proc_macro:Cargo.toml"], - supported_targets = [ - "x86_64-apple-darwin", - "x86_64-unknown-linux-gnu", - ], - ) - - crate_universe( - name = "crate_universe_uses_sys_crate_rust_deps", - cargo_toml_files = [examples_prefix + "//crate_universe/uses_sys_crate:Cargo.toml"], - lockfile = examples_prefix + "//crate_universe/uses_sys_crate:lockfile.lock", - packages = [ - crate.spec( - name = "libc", - semver = "=0.2.76", - ), - ], - supported_targets = [ - "x86_64-apple-darwin", - "x86_64-unknown-linux-gnu", - ], - ) - - crate_universe( - name = "crate_universe_has_aliased_deps_rust_deps", - cargo_toml_files = [examples_prefix + "//crate_universe/has_aliased_deps: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", - ], - ) diff --git a/examples/examples_transitive_deps.bzl b/examples/examples_transitive_deps.bzl index 67410d45c8..bac369466b 100644 --- a/examples/examples_transitive_deps.bzl +++ b/examples/examples_transitive_deps.bzl @@ -8,11 +8,6 @@ load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories") load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains") -load("@crate_universe_basic_rust_deps//:defs.bzl", basic_pinned_rust_install = "pinned_rust_install") -load("@crate_universe_uses_proc_macro_rust_deps//:defs.bzl", uses_proc_macro_pinned_rust_install = "pinned_rust_install") -load("@crate_universe_uses_sys_crate_rust_deps//:defs.bzl", uses_sys_crate_pinned_rust_install = "pinned_rust_install") -load("@crate_universe_has_aliased_deps_rust_deps//:defs.bzl", has_aliased_deps_pinned_rust_install = "pinned_rust_install") - # buildifier: disable=unnamed-macro def transitive_deps(is_top_level = False): """Define transitive dependencies for `rules_rust` examples @@ -41,11 +36,3 @@ def transitive_deps(is_top_level = False): ) node_repositories() - - basic_pinned_rust_install() - - uses_proc_macro_pinned_rust_install() - - uses_sys_crate_pinned_rust_install() - - has_aliased_deps_pinned_rust_install()