-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
...and simplify target names of wrappers
- Loading branch information
Peter Kolloch
committed
Jun 18, 2024
1 parent
80797ab
commit 4ef91dd
Showing
15 changed files
with
182 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Required on windows | ||
common --enable_platform_specific_config | ||
startup --windows_enable_symlinks | ||
build:windows --enable_runfiles | ||
|
||
build --experimental_enable_bzlmod | ||
|
||
# This isn't currently the defaut in Bazel, but we enable it to test we'll be ready if/when it flips. | ||
build --incompatible_disallow_empty_glob | ||
|
||
# Required for cargo_build_script support before Bazel 7 | ||
build --incompatible_merge_fixed_and_default_shell_env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env bash | ||
# ^^^ make IDEs happy | ||
|
||
watch_file bazel-out/bazel_env-opt/bin/env/env/bin | ||
PATH_add bazel-out/bazel_env-opt/bin/env/env/bin | ||
if [[ ! -d bazel-out/bazel_env-opt/bin/env/env/bin ]]; then | ||
log_error "ERROR[bazel_env.bzl]: Run 'bazel run //env:env' to regenerate bazel-out/bazel_env-opt/bin/env/env/bin" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/bazel-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
load("@crates//:defs.bzl", "all_crate_deps") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
rust_binary( | ||
name = "all_crate_deps", | ||
srcs = ["src/main.rs"], | ||
deps = all_crate_deps(normal = True), | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[workspace] | ||
[package] | ||
name = "all_crate_deps" | ||
version = "0.0.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[lib] | ||
path = "/dev/null" | ||
|
||
[dependencies] | ||
anyhow = "1.0.79" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"""bazelbuild/rules_rust - bazel_env/bzlmod example | ||
See https://github.com/buildbuddy-io/bazel_env.bzl. | ||
""" | ||
|
||
module( | ||
name = "all_crate_deps_bzlmod_example", | ||
version = "0.0.0", | ||
) | ||
|
||
bazel_dep(name = "platforms", version = "0.0.9") | ||
|
||
bazel_dep( | ||
name = "rules_rust", | ||
version = "0.0.0", | ||
) | ||
local_path_override( | ||
module_name = "rules_rust", | ||
path = "../..", | ||
) | ||
|
||
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust") | ||
rust.toolchain(edition = "2021") | ||
use_repo( | ||
rust, | ||
"rust_toolchains", | ||
) | ||
|
||
register_toolchains("@rust_toolchains//:all") | ||
|
||
crate = use_extension( | ||
"@rules_rust//crate_universe:extension.bzl", | ||
"crate", | ||
) | ||
crate.from_cargo( | ||
name = "crates", | ||
cargo_lockfile = "//:Cargo.lock", | ||
manifests = ["//:Cargo.toml"], | ||
) | ||
use_repo(crate, "crates") | ||
|
||
bazel_dep(name = "bazel_env.bzl", version = "0.1.1") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# rules_rust with bazel_env | ||
|
||
This example uses [bazel_env.bzl](https://github.com/buildbuddy-io/bazel_env.bzl) to | ||
provide `cargo`, `cargo-clippy`, `rustc` and `rustfmt` from the bazel toolchains | ||
to the user. They will be available directly in the PATH when the user | ||
enters this directory and has [direnv](https://direnv.net/) set up. | ||
|
||
Advantages: | ||
|
||
- The user doesn't have to install the toolchains themselves. | ||
- The tool versions will always match exactly those that bazel uses. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Intentionally blank; using bzlmod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Intentionally blank; enable strict mode for bzlmod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env bash | ||
|
||
# --- begin runfiles.bash initialization v3 --- | ||
# Copy-pasted from the Bazel Bash runfiles library v3. | ||
set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash | ||
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ | ||
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ | ||
source "$0.runfiles/$f" 2>/dev/null || \ | ||
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ | ||
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ | ||
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e | ||
# --- end runfiles.bash initialization v3 --- | ||
|
||
|
||
set -euo pipefail | ||
|
||
# MARK - Functions | ||
|
||
fail() { | ||
echo >&2 "$@" | ||
exit 1 | ||
} | ||
|
||
# MARK - Args | ||
|
||
if [[ "$#" -ne 1 ]]; then | ||
fail "Usage: $0 /path/to/hello_world" | ||
fi | ||
HELLO_WORLD="$(rlocation "$1")" | ||
|
||
# MARK - Test | ||
|
||
OUTPUT="$("${HELLO_WORLD}")" | ||
[[ "${OUTPUT}" == "Hello, world!" ]] || | ||
fail 'Expected "Hello, world!", but was' "${OUTPUT}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
load("@bazel_env.bzl", "bazel_env") | ||
|
||
bazel_env( | ||
name = "env", | ||
tools = { | ||
"cargo": "@rules_rust//tools/upstream_wrapper:cargo", | ||
"cargo-clippy": "@rules_rust//tools/upstream_wrapper:cargo_clippy", | ||
"rustc": "@rules_rust//tools/upstream_wrapper:rustc", | ||
"rustfmt": "@rules_rust//tools/upstream_wrapper:rustfmt", | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2015 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
fn main() -> anyhow::Result<()> { | ||
println!("Hello, world!"); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters