-
Notifications
You must be signed in to change notification settings - Fork 460
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Integrate the examples into cargo-raze * Add the remote examples as well * Add a README doc for remote examples * Fix the build after adding remote README * Remove examples for PR * Enable -f on `rm` so no error if dirs don't exist * Explicitly reset working directory back to original * Rename examples/README.md * Move the command exists check to a function * Make sure `command_exists` actually checks for existence * DIR -> REPO_ROOT
- Loading branch information
1 parent
2f65244
commit f453818
Showing
30 changed files
with
1,966 additions
and
6 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,5 @@ | ||
bazel-bin | ||
bazel-examples | ||
bazel-genfiles | ||
bazel-out | ||
bazel-testlogs |
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 @@ | ||
# Cargo Raze Examples | ||
|
||
The examples directory contains some example usages of Cargo Raze to set up projects for Bazel building. | ||
|
||
# Contributing | ||
|
||
This directory is used in the testing process of Cargo Raze to make sure that practical examples work | ||
during the test process for all contributions. Please do not commit new code here, as it will be destroyed | ||
by the testing process. Instead, new examples should be added to the `smoke_test` directory. |
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 |
---|---|---|
@@ -1,7 +1,79 @@ | ||
#! /usr/bin/env bash | ||
set -e | ||
#!/usr/bin/env bash | ||
|
||
mkdir /tmp/cargo_raze_scratch && cd /tmp/cargo_raze_scratch | ||
git clone https://github.com/acmcarther/cargo-raze-examples | ||
cd cargo-raze-examples | ||
(cd ./internal && ./evaluate-local-raze.sh) | ||
set -eu | ||
|
||
function command_exists { | ||
command -v "$1" >/dev/null 2>&1 || ( echo "Command \`$1\` isn't available. Please install before continuing."; exit 1 ) | ||
} | ||
|
||
PWD="$(pwd)" | ||
|
||
REPO_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
cd "$REPO_ROOT" | ||
|
||
EXAMPLES_DIR="$REPO_ROOT/examples" | ||
TEST_DIR="$REPO_ROOT/smoke_test" | ||
|
||
command_exists "cargo" | ||
command_exists "cargo-vendor" | ||
command_exists "bazel" | ||
|
||
# Clean the `examples` directory | ||
rm -rf "$EXAMPLES_DIR/remote" "$EXAMPLES_DIR/vendored" | ||
cp -r "$TEST_DIR/remote" "$TEST_DIR/vendored" "$EXAMPLES_DIR" | ||
|
||
# Set up the new WORKSPACE file | ||
cat > "$EXAMPLES_DIR/WORKSPACE" << EOF | ||
workspace(name = "io_bazel_rules_rust") | ||
git_repository( | ||
name = "io_bazel_rules_rust", | ||
commit = "ee61ddff0b97cfc36278902e5210d1929ba5b119", | ||
remote = "https://github.com/bazelbuild/rules_rust.git", | ||
) | ||
load("@io_bazel_rules_rust//rust:repositories.bzl", "rust_repositories") | ||
rust_repositories() | ||
EOF | ||
|
||
for ex in $(find $TEST_DIR/remote -maxdepth 1 -type d | tail -n+2); do | ||
name="$(basename "$ex")" | ||
cat >> "$EXAMPLES_DIR/WORKSPACE" << EOF | ||
load("//remote/${name}/cargo:crates.bzl", "${name}_fetch_remote_crates") | ||
${name}_fetch_remote_crates() | ||
EOF | ||
done | ||
|
||
# Run Cargo Vendor over the appropriate projects | ||
for ex in $(find $EXAMPLES_DIR/vendored -maxdepth 1 -type d | tail -n+2); do | ||
echo "Running Cargo Vendor for $(basename "$ex")" | ||
cd "$ex/cargo" | ||
cargo vendor -xq | ||
done | ||
|
||
# Ensure Cargo Raze build is up-to-date | ||
cd "$REPO_ROOT" | ||
echo "Building local Cargo Raze" | ||
cargo build --quiet | ||
RAZE="$REPO_ROOT/target/debug/cargo-raze raze" | ||
for ex in $(find $EXAMPLES_DIR -mindepth 2 -maxdepth 2 -type d); do | ||
echo "Running Cargo Raze for $(basename $ex)" | ||
cd "$ex/cargo" | ||
eval "$RAZE" | ||
done | ||
|
||
# Run the Bazel build for all targets | ||
cd "$EXAMPLES_DIR" | ||
for ex in $(find $EXAMPLES_DIR -mindepth 2 -maxdepth 2 -type d); do | ||
ex_name="$(basename "$ex")" | ||
ex_type="$(basename $(dirname "$ex"))" | ||
bazel_path="//$ex_type/$ex_name:all" | ||
bazel_cargo_path="//$ex_type/$ex_name/cargo:all" | ||
|
||
echo "Running Bazel build for $bazel_path, $bazel_cargo_path" | ||
bazel build "$bazel_path" && bazel build "$bazel_cargo_path" | ||
done | ||
|
||
cd "$PWD" |
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,5 @@ | ||
# Cargo Raze Smoke Test | ||
|
||
The smoke test for Cargo raze consists of some basic examples that are tested to make sure Bazel | ||
functionality hasn't broken for new code. New examples should be created here, but `cargo-vendor` | ||
and `cargo-raze` should *NOT* be run. |
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,13 @@ | ||
# Adding new remote examples | ||
|
||
The smoke test script generates a WORKSPACE file that looks up the `crates.bzl` functions | ||
and assumes that the function name is `<folder>_fetch_remote_crates`. | ||
|
||
In order to make sure that this assertion holds, please make sure set up **Cargo.toml** as such: | ||
|
||
**Cargo.toml** | ||
```toml | ||
|
||
[raze] | ||
gen_workspace_prefix = "<folder>" | ||
``` |
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,10 @@ | ||
load("@io_bazel_rules_rust//rust:rust.bzl", "rust_binary") | ||
|
||
rust_binary( | ||
name = "complicated_cargo_library", | ||
srcs = ["src/main.rs"], | ||
deps = [ | ||
"//remote/complicated_cargo_library/cargo:regex", | ||
"//remote/complicated_cargo_library/cargo:specs", | ||
], | ||
) |
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,3 @@ | ||
# complicated_cargo_library_remote | ||
|
||
This is a "no vendor" version of the complicated_cargo_library. |
Oops, something went wrong.