Skip to content

Commit

Permalink
Restructured project to be buildable with Bazel (#340)
Browse files Browse the repository at this point in the history
* Restructured project to be buildable with Bazel

* Moved `dump_metadata` tool

* Deleted smoke_test directory since examples are more authoritative now

* Added bootstrapped cargo-raze outputs

* Updated Bazel and rules_rust version

* Addressed PR feedback
  • Loading branch information
UebelAndre authored Jan 22, 2021
1 parent c293230 commit 4779bd5
Show file tree
Hide file tree
Showing 418 changed files with 25,611 additions and 4,454 deletions.
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
examples
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.7.1
4.0.0
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
**/bazel-*
**/target/
examples/.bazelversion
26 changes: 5 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ before_install:
- chmod +x install.sh
- ./install.sh --user
- rm -f install.sh
- wget -O ./buildifier https://github.com/bazelbuild/buildtools/releases/download/3.4.0/buildifier
- chmod +x ./buildifier

before_script:
- cargo install cargo-vendor --debug

rust:
- stable
Expand All @@ -36,24 +31,13 @@ matrix:
- rust: nightly

script:
- cd impl
- cargo build --verbose
- cargo test --verbose
- cargo install --debug -f --path .
- cd ../
- ./smoke-test.sh
# Run Buildifier as a linter step for /examples
- |
LINT="$(./buildifier -lint=warn -mode=check -r examples 2>&1)"
if [ -n "${LINT}" ]; then
echo 'Buildifier linting failed for `./examples`.' >&2
echo "${LINT}"
exit 1
fi
rm -f ./buildifier
- bazel build //... && bazel test //...
# Check that /examples has no changes
- |
bazel run //tools:examples_raze
if [ -n "$(git status --porcelain)" ]; then
echo '/examples is out of date. Please run `./smoke-test.sh` locally and commit the changes' >&2
echo '/examples is out of date. Please rerun all tests and commit the changes generated from this command' >&2
exit 1
fi
# Run Buildifier as a linter step
- bazel run //:buildifier_check
39 changes: 39 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier")

alias(
name = "cargo_raze",
actual = "//impl:cargo_raze",
visibility = ["//visibility:public"],
)

alias(
name = "cargo_raze_bin",
actual = "//impl:cargo_raze_bin",
visibility = ["//visibility:public"],
)

alias(
name = "bootstrap",
actual = "//tools:bootstrap",
visibility = ["//visibility:private"],
)

alias(
name = "publish_new_version",
actual = "//tools:publish_new_version",
visibility = ["//visibility:private"],
)

test_suite(
name = "examples_launch_tests",
tests = [
"@cargo_raze_examples//tests:launch_tests",
],
visibility = ["//visibility:private"],
)

buildifier(
name = "buildifier_check",
mode = "check",
visibility = ["//visibility:private"],
)
87 changes: 87 additions & 0 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
workspace(name = "cargo_raze")

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

http_archive(
name = "io_bazel_rules_rust",
sha256 = "93df45afb39622e548f2e7fd1372ad93b0d9f482beed45140c22c9ab0b01fb57",
strip_prefix = "rules_rust-2c678c1e224c03e077f7616baf127f970ddff14d",
urls = [
# Master branch as of 2021-01-21
"https://github.com/bazelbuild/rules_rust/archive/2c678c1e224c03e077f7616baf127f970ddff14d.tar.gz",
],
)

load("@io_bazel_rules_rust//rust:repositories.bzl", "rust_repositories")

rust_repositories(
edition = "2018",
version = "1.49.0",
)

load("//third_party:third_party_repositories.bzl", "third_party_repositories")

third_party_repositories()

load("//third_party:third_party_deps.bzl", "third_party_deps")

third_party_deps()

load("//tools:examples_repository.bzl", "examples_repository")

examples_repository()

load("@cargo_raze_examples//:repositories.bzl", examples_repositories = "repositories")

examples_repositories()

#############################################################################################
# Buildifier
# Note: This should be removed in favor of the buildifier target that can be added in bazelci
#############################################################################################

# buildifier is written in Go and hence needs rules_go to be built.
# See https://github.com/bazelbuild/rules_go for the up to date setup instructions.
http_archive(
name = "io_bazel_rules_go",
sha256 = "d1ffd055969c8f8d431e2d439813e42326961d0942bdf734d2c95dc30c369566",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.24.5/rules_go-v0.24.5.tar.gz",
"https://github.com/bazelbuild/rules_go/releases/download/v0.24.5/rules_go-v0.24.5.tar.gz",
],
)

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

go_rules_dependencies()

go_register_toolchains()

http_archive(
name = "bazel_gazelle",
sha256 = "b85f48fa105c4403326e9525ad2b2cc437babaa6e15a3fc0b1dbab0ab064bc7c",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.22.2/bazel-gazelle-v0.22.2.tar.gz",
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.22.2/bazel-gazelle-v0.22.2.tar.gz",
],
)

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")

gazelle_dependencies(go_repository_default_config = "@//:WORKSPACE.bazel")

http_archive(
name = "com_google_protobuf",
strip_prefix = "protobuf-master",
urls = ["https://github.com/protocolbuffers/protobuf/archive/master.zip"],
)

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

http_archive(
name = "com_github_bazelbuild_buildtools",
strip_prefix = "buildtools-master",
url = "https://github.com/bazelbuild/buildtools/archive/master.zip",
)
1 change: 1 addition & 0 deletions examples/.bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4.0.0
9 changes: 0 additions & 9 deletions examples/DO_NOT_EDIT_HERE.md

This file was deleted.

30 changes: 7 additions & 23 deletions examples/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,37 +1,21 @@
workspace(name = "com_github_google_cargo_raze_examples")
workspace(name = "cargo_raze_examples")

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

http_archive(
name = "io_bazel_rules_rust",
sha256 = "0e2e633bf0f7f25392ffb477d677c88eb34fe70ffae05e3ad92fdd9f8d6579db",
strip_prefix = "rules_rust-bc0578798f50d018ca4278ad5610598c400992c9",
sha256 = "8e1bae501e0df40e8feb2497ebab37c84930bf00b332f8f55315dfc08d85c30a",
strip_prefix = "rules_rust-df18ddbece5b68f86e63414ea4b50d691923039a",
urls = [
# Master branch as of 2020-12-05
"https://github.com/bazelbuild/rules_rust/archive/bc0578798f50d018ca4278ad5610598c400992c9.tar.gz",
# Master branch as of 2021-01-01
"https://github.com/bazelbuild/rules_rust/archive/df18ddbece5b68f86e63414ea4b50d691923039a.tar.gz",
],
)

load("@io_bazel_rules_rust//rust:repositories.bzl", "rust_repositories")

rust_repositories()

load("//remote/binary_dependencies/cargo:crates.bzl", "remote_binary_dependencies_fetch_remote_crates")
load("//:repositories.bzl", "repositories")

remote_binary_dependencies_fetch_remote_crates()

load("//remote/cargo_workspace/cargo:crates.bzl", "remote_cargo_workspace_fetch_remote_crates")

remote_cargo_workspace_fetch_remote_crates()

load("//remote/complicated_cargo_library/cargo:crates.bzl", "remote_complicated_cargo_library_fetch_remote_crates")

remote_complicated_cargo_library_fetch_remote_crates()

load("//remote/no_deps/cargo:crates.bzl", "remote_no_deps_fetch_remote_crates")

remote_no_deps_fetch_remote_crates()

load("//remote/non_cratesio/cargo:crates.bzl", "remote_non_cratesio_fetch_remote_crates")

remote_non_cratesio_fetch_remote_crates()
repositories()
15 changes: 15 additions & 0 deletions examples/repositories.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""This module is the single location for all dependencies for the Cargo Raze examples"""

load("@cargo_raze_examples//remote/binary_dependencies/cargo:crates.bzl", "remote_binary_dependencies_fetch_remote_crates")
load("@cargo_raze_examples//remote/cargo_workspace/cargo:crates.bzl", "remote_cargo_workspace_fetch_remote_crates")
load("@cargo_raze_examples//remote/complicated_cargo_library/cargo:crates.bzl", "remote_complicated_cargo_library_fetch_remote_crates")
load("@cargo_raze_examples//remote/no_deps/cargo:crates.bzl", "remote_no_deps_fetch_remote_crates")
load("@cargo_raze_examples//remote/non_cratesio/cargo:crates.bzl", "remote_non_cratesio_fetch_remote_crates")

def repositories():
"""Defines all the cargo dependencies of the Cargo-raze examples"""
remote_binary_dependencies_fetch_remote_crates()
remote_cargo_workspace_fetch_remote_crates()
remote_complicated_cargo_library_fetch_remote_crates()
remote_no_deps_fetch_remote_crates()
remote_non_cratesio_fetch_remote_crates()
33 changes: 16 additions & 17 deletions examples/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@ successfully as well

load("//tests:launch_test.bzl", "launch_test")

launch_test(target = "//remote/binary_dependencies:binary_dependencies_bin")

launch_test(target = "//remote/cargo_workspace/num_printer:number_printer")

launch_test(target = "//remote/complicated_cargo_library")

launch_test(target = "//remote/no_deps")

launch_test(target = "//remote/non_cratesio:non_cratesio_remote")

launch_test(target = "//vendored/cargo_workspace/num_printer:number_printer")

launch_test(target = "//vendored/complicated_cargo_library")

launch_test(target = "//vendored/hello_cargo_library")

launch_test(target = "//vendored/non_cratesio_library")
test_suite(
name = "launch_tests",
tags = ["small"],
tests = [
launch_test(target = "@cargo_raze_examples//remote/binary_dependencies:binary_dependencies_bin"),
launch_test(target = "@cargo_raze_examples//remote/cargo_workspace/num_printer:number_printer"),
launch_test(target = "@cargo_raze_examples//remote/complicated_cargo_library"),
launch_test(target = "@cargo_raze_examples//remote/no_deps"),
launch_test(target = "@cargo_raze_examples//remote/non_cratesio:non_cratesio_remote"),
launch_test(target = "@cargo_raze_examples//vendored/cargo_workspace/num_printer:number_printer"),
launch_test(target = "@cargo_raze_examples//vendored/complicated_cargo_library"),
launch_test(target = "@cargo_raze_examples//vendored/hello_cargo_library"),
launch_test(target = "@cargo_raze_examples//vendored/non_cratesio_library"),
],
visibility = ["//visibility:public"],
)
12 changes: 10 additions & 2 deletions examples/tests/launch_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
_bash_script = """\
#!/bin/bash
exec "{target}"
if [[ -f "{target}" ]]; then
exec "{target}"
else
exec "external/{target}"
fi
"""

# buildifier: disable=unnamed-macro
Expand All @@ -14,6 +18,8 @@ def launch_test(target):
target (str): The label or package of the target to test. In the case
of the package being passed, the target is assumed to have the
same name.
Returns:
string: The name of the generated test target.
"""

# Account for a missing target (since Buildifier will remove it if it matches the package name)
Expand All @@ -30,7 +36,7 @@ def launch_test(target):
srcs = [target_label],
cmd = "echo '{}' > $@".format(
_bash_script.format(
target = str(target_label).lstrip("/").replace(":", "/"),
target = str(target_label).lstrip("@/").replace("//", "/").replace(":", "/"),
),
),
tags = ["manual"],
Expand All @@ -46,3 +52,5 @@ def launch_test(target):
target_label,
],
)

return name + "_launch_test"
2 changes: 1 addition & 1 deletion examples/vendored/cargo_workspace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ genmode = "Vendored"
default_gen_buildrs = true
package_aliases_dir = "cargo"
experimental_api = true

render_package_aliases = false
22 changes: 0 additions & 22 deletions examples/vendored/cargo_workspace/rng/cargo/BUILD.bazel

This file was deleted.

1 change: 0 additions & 1 deletion impl/.rustfmt.toml

This file was deleted.

Loading

0 comments on commit 4779bd5

Please sign in to comment.