Skip to content

Commit

Permalink
Revert "Update cargo_build_script to work without runfiles support."
Browse files Browse the repository at this point in the history
This reverts commit 77a9de9.
  • Loading branch information
UebelAndre committed Sep 14, 2024
1 parent 77a9de9 commit aa88b9e
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 218 deletions.
4 changes: 1 addition & 3 deletions cargo/cargo_build_script_runner/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ impl BuildScriptOutput {
pub fn outputs_from_command(
cmd: &mut Command,
) -> Result<(Vec<BuildScriptOutput>, Output), Output> {
let child_output = cmd
.output()
.unwrap_or_else(|_| panic!("Unable to start command:\n{:#?}", cmd));
let child_output = cmd.output().expect("Unable to start binary");
if child_output.status.success() {
let reader = BufReader::new(child_output.stdout.as_slice());
let output = Self::outputs_from_reader(reader);
Expand Down
6 changes: 0 additions & 6 deletions cargo/private/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load(":runfiles_enabled.bzl", "runfiles_enabled_build_setting")

bzl_library(
name = "bzl_lib",
srcs = glob(["**/*.bzl"]),
visibility = ["//:__subpackages__"],
)

runfiles_enabled_build_setting(
name = "runfiles_enabled",
visibility = ["//visibility:public"],
)
55 changes: 3 additions & 52 deletions cargo/private/cargo_build_script.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ load(
"find_toolchain",
_name_to_crate_name = "name_to_crate_name",
)
load(":runfiles_enabled.bzl", "is_runfiles_enabled", "runfiles_enabled_attr")

# Reexport for cargo_build_script_wrapper.bzl
name_to_crate_name = _name_to_crate_name
Expand Down Expand Up @@ -199,39 +198,6 @@ def _feature_enabled(ctx, feature_name, default = False):

return default

def _rlocationpath(file, workspace_name):
if file.short_path.startswith("../"):
return file.short_path[len("../"):]

return "{}/{}".format(workspace_name, file.short_path)

def _create_runfiles_dir(ctx, script):
runfiles_dir = ctx.actions.declare_directory("{}.cargo_runfiles".format(ctx.label.name))

workspace_name = ctx.label.workspace_name
if not workspace_name:
workspace_name = ctx.workspace_name

def _runfiles_map(file):
return "{}={}".format(file.path, _rlocationpath(file, workspace_name))

runfiles = script[DefaultInfo].default_runfiles

args = ctx.actions.args()
args.use_param_file("@%s", use_always = True)
args.add(runfiles_dir.path)
args.add_all(runfiles.files, map_each = _runfiles_map, allow_closure = True)

ctx.actions.run(
mnemonic = "CargoBuildScriptRunfilesDir",
executable = ctx.executable._runfiles_maker,
arguments = [args],
inputs = runfiles.files,
outputs = [runfiles_dir],
)

return runfiles_dir

def _cargo_build_script_impl(ctx):
"""The implementation for the `cargo_build_script` rule.
Expand All @@ -249,20 +215,9 @@ def _cargo_build_script_impl(ctx):
flags_out = ctx.actions.declare_file(ctx.label.name + ".flags")
link_flags = ctx.actions.declare_file(ctx.label.name + ".linkflags")
link_search_paths = ctx.actions.declare_file(ctx.label.name + ".linksearchpaths") # rustc-link-search, propagated from transitive dependencies
manifest_dir = "%s.runfiles/%s/%s" % (script.path, ctx.label.workspace_name or ctx.workspace_name, ctx.label.package)
compilation_mode_opt_level = get_compilation_mode_opts(ctx, toolchain).opt_level

build_script_inputs = []

workspace_name = ctx.label.workspace_name
if not workspace_name:
workspace_name = ctx.workspace_name

manifest_dir = "{}.runfiles/{}/{}".format(script.path, workspace_name, ctx.label.package)
if not is_runfiles_enabled(ctx.attr):
runfiles_dir = _create_runfiles_dir(ctx, ctx.attr.script)
build_script_inputs.append(runfiles_dir)
manifest_dir = "{}/{}/{}".format(runfiles_dir.path, workspace_name, ctx.label.package)

streams = struct(
stdout = ctx.actions.declare_file(ctx.label.name + ".stdout.log"),
stderr = ctx.actions.declare_file(ctx.label.name + ".stderr.log"),
Expand Down Expand Up @@ -423,6 +378,7 @@ def _cargo_build_script_impl(ctx):
args.add(streams.stderr)
args.add(ctx.attr.rundir)

build_script_inputs = []
for dep in ctx.attr.link_deps:
if rust_common.dep_info in dep and dep[rust_common.dep_info].dep_env:
dep_env_file = dep[rust_common.dep_info].dep_env
Expand Down Expand Up @@ -564,12 +520,7 @@ cargo_build_script = rule(
"_experimental_symlink_execroot": attr.label(
default = Label("//cargo/settings:experimental_symlink_execroot"),
),
"_runfiles_maker": attr.label(
cfg = "exec",
executable = True,
default = Label("//cargo/private/runfiles_maker"),
),
} | runfiles_enabled_attr(),
},
fragments = ["cpp"],
toolchains = [
str(Label("//rust:toolchain_type")),
Expand Down
74 changes: 0 additions & 74 deletions cargo/private/runfiles_enabled.bzl

This file was deleted.

8 changes: 0 additions & 8 deletions cargo/private/runfiles_maker/BUILD.bazel

This file was deleted.

71 changes: 0 additions & 71 deletions cargo/private/runfiles_maker/runfiles_maker.rs

This file was deleted.

8 changes: 4 additions & 4 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Note that rules_rust bzlmod support is still a work in progress. Most features s
To use `rules_rust` in a project using bzlmod, add the following to your `MODULE.bazel` file:

```python
bazel_dep(name = "rules_rust", version = "0.50.1")
bazel_dep(name = "rules_rust", version = "0.48.0")
```

Don't forget to substitute in your desired release's version number.
Expand All @@ -36,8 +36,8 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# https://github.com/bazelbuild/rules_rust/releases
http_archive(
name = "rules_rust",
integrity = "sha256-Log/YgrGjboS4tCqQPBA58VPyFcnCn/IZm+xxKTZrn0=",
urls = ["https://github.com/bazelbuild/rules_rust/releases/download/0.50.1/rules_rust-v0.50.1.tar.gz"],
integrity = "sha256-Weev1uz2QztBlDA88JX6A1N72SucD1V8lBsaliM0TTg=",
urls = ["https://github.com/bazelbuild/rules_rust/releases/download/0.48.0/rules_rust-v0.48.0.tar.gz"],
)

load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains")
Expand All @@ -57,7 +57,7 @@ To build with a particular version of the Rust compiler, pass that version to [`
rust_register_toolchains(
edition = "2021",
versions = [
"1.79.0",
"1.79.0"
],
)
```
Expand Down
25 changes: 25 additions & 0 deletions examples/crate_universe/cargo_aliases/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# A config file containing Bazel settings

# Required on windows
common --enable_platform_specific_config
startup --windows_enable_symlinks
build:windows --enable_runfiles

# Enable rustfmt
build:strict --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect
build:strict --output_groups=+rustfmt_checks

# Enable clippy
build:strict --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect
build:strict --output_groups=+clippy_checks

# TODO: migrate all dependencies from WORKSPACE to MODULE.bazel
# https://github.com/bazelbuild/rules_rust/issues/2181
common --noenable_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

# This import should always be last to allow users to override
# settings for local development.
try-import %workspace%/user.bazelrc
25 changes: 25 additions & 0 deletions examples/crate_universe/cargo_remote/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# A config file containing Bazel settings

# Required on windows
common --enable_platform_specific_config
startup --windows_enable_symlinks
build:windows --enable_runfiles

# Enable rustfmt
build:strict --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect
build:strict --output_groups=+rustfmt_checks

# Enable clippy
build:strict --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect
build:strict --output_groups=+clippy_checks

# TODO: migrate all dependencies from WORKSPACE to MODULE.bazel
# https://github.com/bazelbuild/rules_rust/issues/2181
common --noenable_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

# This import should always be last to allow users to override
# settings for local development.
try-import %workspace%/user.bazelrc
25 changes: 25 additions & 0 deletions examples/crate_universe/cargo_workspace/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# A config file containing Bazel settings

# Required on windows
common --enable_platform_specific_config
startup --windows_enable_symlinks
build:windows --enable_runfiles

# Enable rustfmt
build:strict --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect
build:strict --output_groups=+rustfmt_checks

# Enable clippy
build:strict --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect
build:strict --output_groups=+clippy_checks

# TODO: migrate all dependencies from WORKSPACE to MODULE.bazel
# https://github.com/bazelbuild/rules_rust/issues/2181
common --noenable_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

# This import should always be last to allow users to override
# settings for local development.
try-import %workspace%/user.bazelrc
Loading

0 comments on commit aa88b9e

Please sign in to comment.