Skip to content

Commit 8e31712

Browse files
committed
Reorganized examples
1 parent 57c23ee commit 8e31712

File tree

113 files changed

+13014
-200
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+13014
-200
lines changed

examples/cross_compile/.bazelrc

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,47 @@
55
## https://bazel.build/docs/best-practices#bazelrc-file
66
###############################################################################
77

8-
###############################################################################
9-
## Build configuration
10-
###############################################################################
8+
# https://bazel.build/reference/command-line-reference#flag--enable_platform_specific_config
9+
common --enable_platform_specific_config
1110

12-
# Don't create bazel-* symlinks in the WORKSPACE directory.
13-
# Instead, set a prefix and put it in .gitignore
14-
# build --symlink_prefix=target-bzl/
11+
# Enable the only currently supported report type
12+
# https://bazel.build/reference/command-line-reference#flag--combined_report
13+
coverage --combined_report=lcov
1514

16-
###############################################################################
17-
## Test configuration
18-
###############################################################################
15+
# Avoid fully cached builds reporting no coverage and failing CI
16+
# https://bazel.build/reference/command-line-reference#flag--experimental_fetch_all_coverage_outputs
17+
coverage --experimental_fetch_all_coverage_outputs
1918

20-
# Reduce test output to just error cases
21-
test --test_output=errors
22-
test --verbose_failures
19+
# Required for some of the tests
20+
# https://bazel.build/reference/command-line-reference#flag--experimental_cc_shared_library
21+
common --experimental_cc_shared_library
2322

2423
###############################################################################
25-
## Common configuration
24+
## Unique configuration groups
2625
###############################################################################
2726

28-
# Enable Bzlmod for every Bazel command
29-
common --enable_bzlmod
27+
# Enable use of the nightly toolchains.
28+
build:nightly --@rules_rust//rust/toolchain/channel=nightly
3029

31-
# Disable the bzlmod lockfile, so we don't accidentally commit MODULE.bazel.lock
32-
common --lockfile_mode=off
30+
# Enable rustfmt for all targets in the workspace
31+
build:rustfmt --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect
32+
build:rustfmt --output_groups=+rustfmt_checks
33+
34+
# Enable clippy for all targets in the workspace
35+
build:clippy --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect
36+
build:clippy --output_groups=+clippy_checks
3337

34-
# Write build outputs in a platform-specific directory;
35-
# avoid outputs being wiped and rewritten when switching between platforms.
36-
common --experimental_platform_in_output_dir
38+
# Enable unpretty for all targets in the workspace
39+
build:unpretty --aspects=@rules_rust//rust:defs.bzl%rust_unpretty_aspect
40+
build:unpretty --output_groups=+rust_unpretty
41+
42+
# `unpretty` requires the nightly toolchain. See tracking issue:
43+
# https://github.com/rust-lang/rust/issues/43364
44+
build:unpretty --config=nightly
45+
46+
###############################################################################
47+
## Incompatibility flags
48+
###############################################################################
3749

3850
# https://github.com/bazelbuild/bazel/issues/8195
3951
build --incompatible_disallow_empty_glob=true
@@ -45,16 +57,14 @@ build --nolegacy_external_runfiles
4557
build --incompatible_autoload_externally=
4658

4759
###############################################################################
48-
## Rust configuration
60+
## Bzlmod
4961
###############################################################################
5062

51-
# Enable rustfmt for all targets in the workspace
52-
build:rustfmt --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect
53-
build:rustfmt --output_groups=+rustfmt_checks
63+
# A configuration for disabling bzlmod.
64+
common:no-bzlmod --noenable_bzlmod --enable_workspace
5465

55-
# Enable clippy for all targets in the workspace
56-
build:clippy --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect
57-
build:clippy --output_groups=+clippy_checks
66+
# Disable the bzlmod lockfile, so we don't accidentally commit MODULE.bazel.lock
67+
common --lockfile_mode=off
5868

5969
###############################################################################
6070
## Custom user flags

examples/cross_compile/.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
/bazel-*
2-
.DS_Store
3-
target-bzl
42
user.bazelrc

examples/cross_compile/BUILD.bazel

Lines changed: 40 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,60 @@
1+
load("@bazel_skylib//rules:build_test.bzl", "build_test")
12
load("@rules_rust//rust:defs.bzl", "rust_binary")
23
load("@rules_shell//shell:sh_test.bzl", "sh_test")
3-
4-
package(default_visibility = ["//visibility:public"])
5-
6-
filegroup(
7-
name = "all",
8-
srcs = [
9-
":hello_world_aarch64",
10-
":hello_world_host",
11-
":hello_world_x86_64",
12-
],
13-
)
4+
load(":musl_utils.bzl", "platform_transition_binary")
145

156
rust_binary(
16-
name = "hello_world_host",
7+
name = "hello",
178
srcs = ["src/main.rs"],
18-
deps = [
19-
"@crates//:lz4-sys",
20-
"@crates//:mimalloc",
21-
],
9+
tags = ["manual"],
2210
)
2311

24-
rust_binary(
25-
name = "hello_world_x86_64",
26-
srcs = ["src/main.rs"],
27-
platform = "//build/platforms:linux-x86_64",
28-
deps = [
29-
"@crates//:lz4-sys",
30-
"@crates//:mimalloc",
31-
],
12+
platform_transition_binary(
13+
name = "hello_linux_x86_64_musl",
14+
binary = ":hello",
15+
platform = "//platforms:linux_x86_64_musl",
3216
)
3317

34-
rust_binary(
35-
name = "hello_world_aarch64",
36-
srcs = ["src/main.rs"],
37-
platform = "//build/platforms:linux-aarch64",
38-
deps = [
39-
"@crates//:lz4-sys",
40-
"@crates//:mimalloc",
41-
],
42-
)
43-
44-
# Test if the host binary works.
45-
# Note, we cannot test for platform since Bazel determines the host platform automatically
4618
sh_test(
47-
name = "test_hello_world_host",
48-
srcs = ["test_hello_world.sh"],
19+
name = "hello_linux_x86_64_musl_test",
20+
srcs = ["hello_linux_musl_test.sh"],
4921
args = [
50-
"$(rlocationpath :hello_world_host)",
51-
],
52-
data = [
53-
":hello_world_host",
54-
],
55-
deps = [
56-
"@bazel_tools//tools/bash/runfiles",
22+
"$(rootpath :hello_linux_x86_64_musl)",
23+
"'ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), static-pie linked'",
5724
],
25+
data = [":hello_linux_x86_64_musl"],
5826
)
5927

60-
# Test the for x86_64 architecture
61-
sh_test(
62-
name = "test_linux_x86_64",
63-
srcs = ["test_platform.sh"],
64-
args = [
65-
"$(rootpath :hello_world_x86_64)",
66-
"x86_64",
67-
],
68-
data = [
69-
":hello_world_x86_64",
70-
],
71-
deps = [
72-
"@bazel_tools//tools/bash/runfiles",
73-
],
28+
platform_transition_binary(
29+
name = "hello_linux_arm64_musl",
30+
binary = ":hello",
31+
platform = "//platforms:linux_arm64_musl",
7432
)
7533

76-
# Test for ARM architecture
7734
sh_test(
78-
name = "test_linux_arm64",
79-
srcs = ["test_platform.sh"],
35+
name = "hello_linux_arm64_musl_test",
36+
srcs = ["hello_linux_musl_test.sh"],
8037
args = [
81-
"$(rootpath :hello_world_aarch64)",
82-
"aarch64",
83-
],
84-
data = [
85-
":hello_world_aarch64",
86-
],
87-
deps = [
88-
"@bazel_tools//tools/bash/runfiles",
38+
"$(rootpath :hello_linux_arm64_musl)",
39+
"'ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked'",
8940
],
41+
data = [":hello_linux_arm64_musl"],
42+
)
43+
44+
rust_binary(
45+
name = "keyring",
46+
srcs = ["src/keyring.rs"],
47+
tags = ["manual"],
48+
deps = ["@cu//:keyring"],
49+
)
50+
51+
platform_transition_binary(
52+
name = "keyring_linux_x86_64_musl",
53+
binary = ":keyring",
54+
platform = "//platforms:linux_x86_64_musl",
55+
)
56+
57+
build_test(
58+
name = "keyring_linux_x86_64_musl_build_test",
59+
targets = [":keyring_linux_x86_64_musl"],
9060
)
File renamed without changes.

0 commit comments

Comments
 (0)