Skip to content

Commit 389bf8d

Browse files
committed
Remove unnecessary external dependencies
1 parent 9cdb86c commit 389bf8d

File tree

10 files changed

+173
-54
lines changed

10 files changed

+173
-54
lines changed

examples/crate_universe/WORKSPACE.bazel

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -629,19 +629,6 @@ load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_depende
629629

630630
rules_foreign_cc_dependencies()
631631

632-
http_archive(
633-
name = "aspect_bazel_lib",
634-
sha256 = "f5ea76682b209cc0bd90d0f5a3b26d2f7a6a2885f0c5f615e72913f4805dbb0d",
635-
strip_prefix = "bazel-lib-2.5.0",
636-
url = "https://github.com/aspect-build/bazel-lib/releases/download/v2.5.0/bazel-lib-v2.5.0.tar.gz",
637-
)
638-
639-
load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies", "aspect_bazel_lib_register_toolchains")
640-
641-
aspect_bazel_lib_dependencies()
642-
643-
aspect_bazel_lib_register_toolchains()
644-
645632
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
646633

647634
git_repository(

examples/crate_universe/complicated_dependencies/BUILD.bazel

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
load("@aspect_bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory")
21
load("@bazel_skylib//rules:build_test.bzl", "build_test")
2+
load("@rules_rust//rust:defs.bzl", "rust_binary")
3+
load(":boringssl_utils.bzl", "boringssl_build_script_dir")
4+
5+
rust_binary(
6+
name = "build_script_dir_maker",
7+
srcs = ["build_script_dir_maker.rs"],
8+
edition = "2021",
9+
)
310

411
# This target lays out the output needed from boringssl in the directory structure needed by the boring-sys build script.
5-
copy_to_directory(
12+
boringssl_build_script_dir(
613
name = "boringssl_gen_dir",
7-
srcs = [
8-
"@boringssl//:crypto",
9-
"@boringssl//:ssl",
10-
],
1114
out = "boringssl_gen_dir_out",
12-
include_external_repositories = ["*"],
13-
replace_prefixes = {
14-
"libcrypto.a": "build/libcrypto.a",
15-
"libssl.a": "build/libssl.a",
16-
},
15+
crypto = "@boringssl//:crypto",
16+
ssl = "@boringssl//:ssl",
1717
visibility = ["//visibility:public"],
1818
)
1919

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""BoringSSL Utils"""
2+
3+
def _boringssl_build_script_dir_impl(ctx):
4+
output = ctx.actions.declare_directory(ctx.attr.out)
5+
6+
ssl = ctx.file.ssl
7+
crypto = ctx.file.crypto
8+
9+
inputs = depset([ssl, crypto])
10+
11+
ctx.actions.run(
12+
executable = ctx.executable._maker,
13+
oututs = [output],
14+
inputs = inputs,
15+
env = {
16+
"ARG_CRYPTO": crypto.path,
17+
"ARG_OUTPUT": output.path,
18+
"ARG_SSL": ssl.path,
19+
},
20+
)
21+
22+
return [DefaultInfo(
23+
files = depset([output]),
24+
runfiles = ctx.runfiles([output]),
25+
)]
26+
27+
boringssl_build_script_dir = rule(
28+
doc = "A utility rule for building directories compatible with its `cargo_build_script` target.",
29+
implementation = _boringssl_build_script_dir_impl,
30+
attrs = {
31+
"crypto": attr.label(
32+
doc = "The `crypto`/`libcrypto` library.",
33+
allow_single_file = True,
34+
mandatory = True,
35+
),
36+
"out": attr.string(
37+
doc = "The name of the output directory.",
38+
mandatory = True,
39+
),
40+
"ssl": attr.label(
41+
doc = "The `ssl`/`libssl` library.",
42+
allow_single_file = True,
43+
mandatory = True,
44+
),
45+
"_maker": attr.label(
46+
cfg = "exec",
47+
executable = True,
48+
default = Label("//crate_universe/complicated_dependencies:build_script_dir_maker"),
49+
),
50+
},
51+
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//! A utility script for the "complicated dependencies" example.
2+
3+
use std::{env, fs};
4+
use std::path::PathBuf;
5+
6+
fn main() {
7+
let ssl = PathBuf::from(env::var("ARG_SSL").unwrap());
8+
let crypto = PathBuf::from(env::var("ARG_CRYPTO").unwrap());
9+
let output = PathBuf::from(env::var("ARG_OUTPUT").unwrap());
10+
11+
let build_dir = output.join("build")
12+
13+
fs::create_dir_all(&build_dir).unwrap();
14+
15+
fs::copy(ssl, build_dir.join(ssl.file_name().unwrap())).unwrap();
16+
fs::copy(crypto, build_dir.join(crypto.file_name().unwrap())).unwrap();
17+
}

examples/musl_cross_compiling/BUILD.bazel

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_binary")
21
load("@bazel_skylib//rules:build_test.bzl", "build_test")
32
load("@rules_rust//rust:defs.bzl", "rust_binary")
3+
load(":musl_utils.bzl", "platform_transition_binary")
44

55
rust_binary(
66
name = "hello",
@@ -11,7 +11,7 @@ rust_binary(
1111
platform_transition_binary(
1212
name = "hello_linux_x86_64_musl",
1313
binary = ":hello",
14-
target_platform = "//platforms:linux_x86_64_musl",
14+
platform = "//platforms:linux_x86_64_musl",
1515
)
1616

1717
sh_test(
@@ -27,7 +27,7 @@ sh_test(
2727
platform_transition_binary(
2828
name = "hello_linux_arm64_musl",
2929
binary = ":hello",
30-
target_platform = "//platforms:linux_arm64_musl",
30+
platform = "//platforms:linux_arm64_musl",
3131
)
3232

3333
sh_test(
@@ -50,7 +50,7 @@ rust_binary(
5050
platform_transition_binary(
5151
name = "keyring_linux_x86_64_musl",
5252
binary = ":keyring",
53-
target_platform = "//platforms:linux_x86_64_musl",
53+
platform = "//platforms:linux_x86_64_musl",
5454
)
5555

5656
build_test(

examples/musl_cross_compiling/WORKSPACE.bazel

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,6 @@ rust_register_toolchains(
104104

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

107-
http_archive(
108-
name = "aspect_bazel_lib",
109-
sha256 = "f5ea76682b209cc0bd90d0f5a3b26d2f7a6a2885f0c5f615e72913f4805dbb0d",
110-
strip_prefix = "bazel-lib-2.5.0",
111-
url = "https://github.com/aspect-build/bazel-lib/releases/download/v2.5.0/bazel-lib-v2.5.0.tar.gz",
112-
)
113-
114-
load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies", "aspect_bazel_lib_register_toolchains")
115-
116-
aspect_bazel_lib_dependencies()
117-
118-
aspect_bazel_lib_register_toolchains()
119-
120107
http_archive(
121108
name = "musl_toolchains",
122109
sha256 = "1e6cf99f35277dbb9c3b341a9986d0f33cf70e0cc76a58f062d2d9b7ab56eeeb",
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""Utility rules"""
2+
3+
def _transition_platform_impl(_, attr):
4+
return {"//command_line_option:platforms": str(attr.platform)}
5+
6+
_transition_platform = transition(
7+
implementation = _transition_platform_impl,
8+
inputs = [],
9+
outputs = ["//command_line_option:platforms"],
10+
)
11+
12+
def _platform_transition_binary_impl(ctx):
13+
default_info = ctx.attr.binary[DefaultInfo]
14+
executable = ctx.executable.binary
15+
16+
output = ctx.actions.declare_file("{}.{}".format(ctx.label.name, executable.extension).rstrip("."))
17+
ctx.actions.symlink(
18+
output = output,
19+
target_file = executable,
20+
is_executable = True,
21+
)
22+
files = depset(direct = [executable], transitive = [default_info.files])
23+
runfiles = ctx.runfiles([output, executable]).merge(default_info.default_runfiles)
24+
25+
return [DefaultInfo(
26+
files = files,
27+
runfiles = runfiles,
28+
executable = output,
29+
)]
30+
31+
platform_transition_binary = rule(
32+
doc = "Transitions a target to the provided platform.",
33+
implementation = _platform_transition_binary_impl,
34+
attrs = {
35+
"binary": attr.label(
36+
doc = "The target to transition",
37+
allow_single_file = True,
38+
cfg = _transition_platform,
39+
executable = True,
40+
),
41+
"platform": attr.label(
42+
doc = "The platform to transition to.",
43+
mandatory = True,
44+
),
45+
"_allowlist_function_transition": attr.label(
46+
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
47+
),
48+
},
49+
executable = True,
50+
)

examples/zig_cross_compiling/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_filegroup")
21
load("@crate_index//:defs.bzl", "aliases", "all_crate_deps")
32
load("@rules_rust//cargo:defs.bzl", "cargo_build_script")
43
load("@rules_rust//rust:defs.bzl", "rust_binary")
4+
load(":zig_utils.bzl", "platform_transition_filegroup")
55

66
rust_binary(
77
name = "uses_ring",
@@ -33,5 +33,5 @@ platform(
3333
platform_transition_filegroup(
3434
name = "uses_ring_arm",
3535
srcs = [":uses_ring"],
36-
target_platform = "aarch64_linux",
36+
platform = "aarch64_linux",
3737
)

examples/zig_cross_compiling/WORKSPACE.bazel

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,3 @@ crates_repository(
7070
load("@crate_index//:defs.bzl", "crate_repositories")
7171

7272
crate_repositories()
73-
74-
http_archive(
75-
name = "aspect_bazel_lib",
76-
sha256 = "3534a27621725fbbf1d3e53daa0c1dda055a2732d9031b8c579f917d7347b6c4",
77-
strip_prefix = "bazel-lib-1.16.1",
78-
url = "https://github.com/aspect-build/bazel-lib/archive/refs/tags/v1.16.1.tar.gz",
79-
)
80-
81-
load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies")
82-
83-
aspect_bazel_lib_dependencies()
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""Utility rules"""
2+
3+
def _transition_platform_impl(_, attr):
4+
return {"//command_line_option:platforms": str(attr.platform)}
5+
6+
_transition_platform = transition(
7+
implementation = _transition_platform_impl,
8+
inputs = [],
9+
outputs = ["//command_line_option:platforms"],
10+
)
11+
12+
def _platform_transition_filegroup_impl(ctx):
13+
files = depset(transitive = [src[DefaultInfo].files for src in ctx.attr.srcs])
14+
runfiles = ctx.runfiles().merge_all([src[DefaultInfo].default_runfiles for src in ctx.attr.srcs])
15+
16+
return [DefaultInfo(
17+
files = files,
18+
runfiles = runfiles,
19+
)]
20+
21+
platform_transition_filegroup = rule(
22+
doc = "Transitions a target to the provided platform.",
23+
implementation = _platform_transition_filegroup_impl,
24+
attrs = {
25+
"platform": attr.label(
26+
doc = "The platform to transition to.",
27+
mandatory = True,
28+
),
29+
"srcs": attr.label_list(
30+
doc = "The targets to transition",
31+
allow_files = True,
32+
cfg = _transition_platform,
33+
),
34+
"_allowlist_function_transition": attr.label(
35+
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
36+
),
37+
},
38+
)

0 commit comments

Comments
 (0)