Skip to content

Commit

Permalink
Added crate_universe examples to CI (#707)
Browse files Browse the repository at this point in the history
* Added crate_universe examples to CI

* Update crate_universe/bootstrap.bzl

Co-authored-by: Daniel Wagner-Hall <[email protected]>

* Updated docs

* Remove crate_universe.bazelrc

* Updated attribute names

* Deleted example lockfile

Co-authored-by: Daniel Wagner-Hall <[email protected]>
  • Loading branch information
UebelAndre and illicitonion authored Apr 27, 2021
1 parent 374c75e commit a04ff41
Show file tree
Hide file tree
Showing 17 changed files with 342 additions and 786 deletions.
48 changes: 47 additions & 1 deletion .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,53 @@ tasks:
# - "--linkopt=-fuse-ld=lld"
build_targets: *default_linux_targets
test_targets: *default_linux_targets

crate_universe_examples_ubuntu2004:
name: Crate Universe Examples
platform: ubuntu2004
environment:
RULES_RUST_CRATE_UNIVERSE_BOOTSTRAP: true
working_directory: examples/crate_universe
build_targets:
- "//..."
test_targets:
- "//..."
crate_universe_rbe_ubuntu1604:
name: Crate Universe Examples
platform: rbe_ubuntu1604
environment:
RULES_RUST_CRATE_UNIVERSE_BOOTSTRAP: true
working_directory: examples/crate_universe
build_targets:
- "//..."
test_targets:
- "//..."
crate_universe_examples_macos:
name: Crate Universe Examples
platform: macos
environment:
RULES_RUST_CRATE_UNIVERSE_BOOTSTRAP: true
working_directory: examples/crate_universe
build_targets:
- "//..."
test_targets:
- "//..."
crate_universe_examples_windows:
name: Crate Universe Examples
platform: windows
environment:
RULES_RUST_CRATE_UNIVERSE_BOOTSTRAP: true
working_directory: examples/crate_universe
crate_universe_windows_targets: &crate_universe_windows_targets
- "//..."
# TODO: There are windows specific build issues in the generated
# depednencies. This should be fixed and all testing enabled.
- "-//basic:test"
- "-//has_aliased_deps/..."
- "-//uses_proc_macro/..."
- "-//uses_sys_crate/..."
build_targets: *crate_universe_windows_targets
# TODO: fix test targets in `crate_universe_windows_targets`
# test_targets: *crate_universe_windows_targets
buildifier:
version: latest
warnings: "all"
3 changes: 0 additions & 3 deletions .bazelrc

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
/examples/bazel-*
/examples/crate_universe/*/bazel-*
/docs/bazel-*
crate_universe.bazelrc

# rustfmt
*.rs.bk
Expand Down
7 changes: 3 additions & 4 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "bazel_toolchains",
sha256 = "d8c2f20deb2f6143bac792d210db1a4872102d81529fe0ea3476c1696addd7ff",
strip_prefix = "bazel-toolchains-0.28.3",
sha256 = "1adf7a8e9901287c644dcf9ca08dd8d67a69df94bedbd57a841490a84dc1e9ed",
strip_prefix = "bazel-toolchains-5.0.0",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-toolchains/archive/0.28.3.tar.gz",
"https://github.com/bazelbuild/bazel-toolchains/archive/0.28.3.tar.gz",
"https://github.com/bazelbuild/bazel-toolchains/archive/refs/tags/v5.0.0.tar.gz",
],
)

Expand Down
35 changes: 0 additions & 35 deletions bootstrap.sh

This file was deleted.

10 changes: 10 additions & 0 deletions crate_universe/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

package(default_visibility = ["//visibility:public"])

exports_files([
"Cargo.toml",
"Cargo.lock",
])

bzl_library(
name = "rules",
srcs = glob(["**/*.bzl"]),
deps = ["//crate_universe/private:bzl_srcs"],
)

filegroup(
name = "resolver_srcs",
srcs = glob(["srcs/**"]),
)
103 changes: 103 additions & 0 deletions crate_universe/bootstrap.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
"""A module for declaraing a repository for bootstrapping crate_universe"""

load("//crate_universe/private:util.bzl", "get_host_info")

BOOTSTRAP_ENV_VAR = "RULES_RUST_CRATE_UNIVERSE_BOOTSTRAP"

_INSTALL_SCRIPT_CONTENT = """\
#!/bin/bash
set -euo pipefail
cp "${CRATE_RESOLVER_BIN}" "$@"
"""

_BUILD_FILE_CONTENT = """\
package(default_visibility = ["//visibility:public"])
exports_files(["release/crate_universe_resolver{ext}"])
sh_binary(
name = "install",
data = [
":release/crate_universe_resolver{ext}",
],
env = {{
"CRATE_RESOLVER_BIN": "$(execpath :release/crate_universe_resolver{ext})",
}},
srcs = ["install.sh"],
)
"""

def _crate_universe_resolver_bootstrapping_impl(repository_ctx):
# no-op if there has been no request for bootstrapping
if BOOTSTRAP_ENV_VAR not in repository_ctx.os.environ:
repository_ctx.file("BUILD.bazel")
return

resolver_triple, toolchain_repo, extension = get_host_info(repository_ctx)

cargo_path = repository_ctx.path(Label(toolchain_repo + "//:bin/cargo" + extension))
rustc_path = repository_ctx.path(Label(toolchain_repo + "//:bin/rustc" + extension))

repository_dir = repository_ctx.path(".")
resolver_path = repository_ctx.path("release/crate_universe_resolver" + extension)

args = [
cargo_path,
"build",
"--release",
"--locked",
"--target-dir",
repository_dir,
"--manifest-path",
repository_ctx.path(repository_ctx.attr.cargo_toml),
]

repository_ctx.report_progress("bootstrapping crate_universe_resolver")
result = repository_ctx.execute(
args,
environment = {
"RUSTC": str(rustc_path),
},
quiet = False,
)

if result.return_code != 0:
fail("exit_code: {}".format(
result.return_code,
))

repository_ctx.file("install.sh", _INSTALL_SCRIPT_CONTENT)

repository_ctx.file("BUILD.bazel", _BUILD_FILE_CONTENT.format(
ext = extension,
))

_crate_universe_resolver_bootstrapping = repository_rule(
doc = "A rule for bootstrapping a crate_universe_resolver binary using [Cargo](https://doc.rust-lang.org/cargo/)",
implementation = _crate_universe_resolver_bootstrapping_impl,
attrs = {
"cargo_lockfile": attr.label(
doc = "The lockfile of the crate_universe resolver",
allow_single_file = ["Cargo.lock"],
default = Label("//crate_universe:Cargo.lock"),
),
"cargo_toml": attr.label(
doc = "The path of the crate_universe resolver manifest (`Cargo.toml` file)",
allow_single_file = ["Cargo.toml"],
default = Label("//crate_universe:Cargo.toml"),
),
"srcs": attr.label(
doc = "Souces to the crate_universe resolver",
allow_files = True,
default = Label("//crate_universe:resolver_srcs"),
),
},
environ = [BOOTSTRAP_ENV_VAR],
)

def crate_universe_bootstrap():
_crate_universe_resolver_bootstrapping(
name = "rules_rust_crate_universe_bootstrap",
)
Loading

0 comments on commit a04ff41

Please sign in to comment.