Skip to content

Commit

Permalink
Move raw_cargo into private package
Browse files Browse the repository at this point in the history
  • Loading branch information
cameron-martin committed Feb 18, 2023
1 parent a3d7796 commit 53b6b54
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ bazel_dep(name = "bazel_skylib", version = "1.2.0")
bazel_dep(name = "apple_support", version = "0.13.0")

# Load tinyjson without using the process wrapper
raw_cargo = use_extension("//:extensions.bzl", "raw_cargo")
raw_cargo = use_extension("//rust/private:extensions.bzl", "raw_cargo")

raw_cargo.crate(
name = "tinyjson",
Expand Down
31 changes: 0 additions & 31 deletions extensions.bzl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"Module extensions for using rules_rust with bzlmod"

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

def _toolchains_impl(ctx):
mod = ctx.modules[0]
Expand All @@ -13,33 +12,3 @@ toolchains = module_extension(
implementation = _toolchains_impl,
tag_classes = {"toolchain": toolchains_toolchain},
)

def _create_build_file_content(name):
return """
load("@rules_rust//rust/private:rust.bzl", "rust_library_without_process_wrapper")
rust_library_without_process_wrapper(
name = "{}",
srcs = glob(["src/*.rs"]),
edition = "2018",
visibility = ["@rules_rust//util/process_wrapper:__pkg__"],
)
""".format(name)

def _raw_cargo_impl(ctx):
for mod in ctx.modules:
for crate in mod.tags.crate:
http_archive(
name = "raw_cargo_{}_{}".format(crate.name, crate.version.replace(".", "_")),
sha256 = crate.sha256,
url = "https://crates.io/api/v1/crates/{}/{}/download".format(crate.name, crate.version),
strip_prefix = "{}-{}".format(crate.name, crate.version),
type = "tar.gz",
build_file_content = _create_build_file_content(crate.name),
)

raw_cargo_crate = tag_class(attrs = {"name": attr.string(), "version": attr.string(), "sha256": attr.string()})
raw_cargo = module_extension(
implementation = _raw_cargo_impl,
tag_classes = {"crate": raw_cargo_crate},
)
31 changes: 31 additions & 0 deletions rust/private/extensions.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

def _create_build_file_content(name):
return """
load("@rules_rust//rust/private:rust.bzl", "rust_library_without_process_wrapper")
rust_library_without_process_wrapper(
name = "{}",
srcs = glob(["src/*.rs"]),
edition = "2018",
visibility = ["@rules_rust//util/process_wrapper:__pkg__"],
)
""".format(name)

def _raw_cargo_impl(ctx):
for mod in ctx.modules:
for crate in mod.tags.crate:
http_archive(
name = "raw_cargo_{}_{}".format(crate.name, crate.version.replace(".", "_")),
sha256 = crate.sha256,
url = "https://crates.io/api/v1/crates/{}/{}/download".format(crate.name, crate.version),
strip_prefix = "{}-{}".format(crate.name, crate.version),
type = "tar.gz",
build_file_content = _create_build_file_content(crate.name),
)

raw_cargo_crate = tag_class(attrs = {"name": attr.string(), "version": attr.string(), "sha256": attr.string()})
raw_cargo = module_extension(
implementation = _raw_cargo_impl,
tag_classes = {"crate": raw_cargo_crate},
)

0 comments on commit 53b6b54

Please sign in to comment.