Skip to content

Commit

Permalink
Merge branch 'main' into runfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
UebelAndre committed Jun 1, 2021
2 parents 687b486 + 52c87aa commit 38a74b0
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 26 deletions.
27 changes: 18 additions & 9 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,24 @@ tasks:
ubuntu1604:
build_targets: *default_linux_targets
test_targets: *default_linux_targets
build_flags:
- "--config=rustfmt"
ubuntu1804:
build_targets: *default_linux_targets
test_targets:
- "..."
- "@examples//..."
# TODO: Switch manual tag to platform constraint after bazel 4.0.
- "//test/versioned_dylib:versioned_dylib_test"
build_flags:
- "--config=rustfmt"
ubuntu2004:
name: "Minimum Supported Version"
bazel: "3.5.0"
build_targets: *default_linux_targets
test_targets: *default_linux_targets
build_flags:
- "--config=rustfmt"
macos:
osx_targets: &osx_targets
- "--" # Allows negative patterns; hack for https://github.com/bazelbuild/continuous-integration/pull/245
Expand All @@ -34,6 +40,8 @@ tasks:
- "-@examples//ffi/rust_calling_c/simple/..."
build_targets: *osx_targets
test_targets: *osx_targets
build_flags:
- "--config=rustfmt"
rbe_ubuntu1604:
test_targets:
- "--" # Allows negative patterns; hack for https://github.com/bazelbuild/continuous-integration/pull/245
Expand All @@ -48,9 +56,12 @@ tasks:
- "-@examples//ffi/rust_calling_c/simple/..."
# See https://github.com/bazelbuild/bazel/issues/9987
- "-@examples//ffi/rust_calling_c:matrix_dylib_test"
build_flags:
- "--config=rustfmt"
windows:
build_flags:
- "--enable_runfiles" # this is not enabled by default on windows and is necessary for the cargo build scripts
- "--config=rustfmt"
windows_targets: &windows_targets
- "--" # Allows negative patterns; hack for https://github.com/bazelbuild/continuous-integration/pull/245
- "..."
Expand All @@ -76,6 +87,8 @@ tasks:
working_directory: examples
test_targets:
- //...
build_flags:
- "--config=rustfmt"
docs_linux:
name: Docs
platform: ubuntu1804
Expand All @@ -98,15 +111,6 @@ tasks:
platform: ubuntu1804
shell_commands:
- ./test/clippy/clippy_failure_test.sh
rustfmt_examples:
name: Rustfmt on Examples
platform: ubuntu2004
working_directory: examples
build_flags:
- "--aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect"
- "--output_groups=rustfmt_checks"
build_targets:
- //...
rustfmt_failure:
name: Negative Rustfmt Tests
platform: ubuntu2004
Expand Down Expand Up @@ -141,6 +145,8 @@ tasks:
- "//..."
test_targets:
- "//..."
build_flags:
- "--config=rustfmt"
crate_universe_examples_macos:
name: Crate Universe Examples
platform: macos
Expand All @@ -151,6 +157,8 @@ tasks:
- "//..."
test_targets:
- "//..."
build_flags:
- "--config=rustfmt"
crate_universe_examples_windows:
name: Crate Universe Examples
platform: windows
Expand All @@ -159,6 +167,7 @@ tasks:
working_directory: examples/crate_universe
build_flags:
- "--enable_runfiles" # this is not enabled by default on windows and is necessary for the cargo build scripts
- "--config=rustfmt"
crate_universe_windows_targets: &crate_universe_windows_targets
- "//..."
# TODO: There are windows specific build issues in the generated
Expand Down
6 changes: 6 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# `.bazelrc` is a Bazel configuration file.
# https://docs.bazel.build/versions/master/best-practices.html#using-the-bazelrc-file

# Enable rustfmt for all targets in the workspace
build:rustfmt --aspects=//rust:defs.bzl%rustfmt_aspect
build:rustfmt --output_groups=+rustfmt_checks
2 changes: 1 addition & 1 deletion cargo/cargo_build_script_runner/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//rust:rust.bzl", "rust_binary", "rust_library", "rust_test")
load("//rust:defs.bzl", "rust_binary", "rust_library", "rust_test")

rust_library(
name = "cargo_build_script_output_parser",
Expand Down
6 changes: 6 additions & 0 deletions examples/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# `.bazelrc` is a Bazel configuration file.
# https://docs.bazel.build/versions/master/best-practices.html#using-the-bazelrc-file

# Enable rustfmt for all targets in the workspace
build:rustfmt --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect
build:rustfmt --output_groups=+rustfmt_checks
6 changes: 6 additions & 0 deletions examples/crate_universe/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# `.bazelrc` is a Bazel configuration file.
# https://docs.bazel.build/versions/master/best-practices.html#using-the-bazelrc-file

# Enable rustfmt for all targets in the workspace
build:rustfmt --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect
build:rustfmt --output_groups=+rustfmt_checks
4 changes: 4 additions & 0 deletions rust/private/rustfmt.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def _find_rustfmtable_srcs(target, aspect_ctx = None):
if rust_common.crate_info not in target:
return []

# Ignore external targets
if target.label.workspace_root.startswith("external"):
return []

# Targets annotated with `norustfmt` will not be formatted
if aspect_ctx and "norustfmt" in aspect_ctx.rule.attr.tags:
return []
Expand Down
2 changes: 2 additions & 0 deletions test/rustfmt/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ rust_binary(
name = "unformatted_2018",
srcs = ["srcs/2018/unformatted.rs"],
edition = "2018",
tags = ["norustfmt"],
)

rustfmt_test(
Expand All @@ -42,6 +43,7 @@ rust_binary(
name = "unformatted_2015",
srcs = ["srcs/2015/unformatted.rs"],
edition = "2015",
tags = ["norustfmt"],
)

rustfmt_test(
Expand Down
28 changes: 15 additions & 13 deletions test/rustfmt/rustfmt_failure_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,7 @@ function check_build_result() {
fi
}

function test_all() {
local -r TEST_OK=0
local -r TEST_FAILED=3

check_build_result $TEST_FAILED test_unformatted_2015
check_build_result $TEST_FAILED test_unformatted_2018
check_build_result $TEST_OK test_formatted_2015
check_build_result $TEST_OK test_formatted_2018
}

function test_apply() {
function test_all_and_apply() {
local -r TEST_OK=0
local -r TEST_FAILED=3

Expand All @@ -62,8 +52,21 @@ load("@rules_rust//rust:repositories.bzl", "rust_repositories")
rust_repositories()
EOF

# Drop the 'norustfmt' tags
if [ "$(uname)" == "Darwin" ]; then
SEDOPTS=(-i '' -e)
else
SEDOPTS=(-i)
fi
sed ${SEDOPTS[@]} 's/"norustfmt"//' "${new_workspace}/test/rustfmt/BUILD.bazel"

pushd "${new_workspace}"

check_build_result $TEST_FAILED test_unformatted_2015
check_build_result $TEST_FAILED test_unformatted_2018
check_build_result $TEST_OK test_formatted_2015
check_build_result $TEST_OK test_formatted_2018

# Format a specific target
bazel run @rules_rust//tools/rustfmt -- //test/rustfmt:unformatted_2018

Expand All @@ -85,5 +88,4 @@ EOF
rm -rf "${temp_dir}"
}

test_all
test_apply
test_all_and_apply
1 change: 1 addition & 0 deletions test/unit/use_libtest_harness/mytest.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 1 addition & 1 deletion test/unit/use_libtest_harness/mytest_noharness.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fn main() {}
fn main() {}
2 changes: 1 addition & 1 deletion tools/runfiles/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load(
"//rust:rust.bzl",
"//rust:defs.bzl",
"rust_doc_test",
"rust_library",
"rust_test",
Expand Down
4 changes: 3 additions & 1 deletion tools/rust_analyzer/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ fn main() -> anyhow::Result<()> {
let mut generated_rust_project = bazel_bin.clone();

if let Some(repository_name) = label.repository_name {
generated_rust_project = generated_rust_project.join("external").join(repository_name);
generated_rust_project = generated_rust_project
.join("external")
.join(repository_name);
}

for package in label.packages() {
Expand Down

0 comments on commit 38a74b0

Please sign in to comment.