-
Notifications
You must be signed in to change notification settings - Fork 432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update cargo_build_script
to work without runfiles support.
#2871
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
600ed1c
Update `cargo_build_script` to work without runfiles support.
UebelAndre 48e6cd3
log error
UebelAndre d7d990b
fix ambiguous matches
UebelAndre f858135
Address some windows build issues
UebelAndre 86f327c
fix batch command
UebelAndre 517e31e
Add explicit test flags
UebelAndre 092dbbf
Better error message
UebelAndre 2282fe1
Fixing tests
UebelAndre 5b98341
Additional windows fixes
UebelAndre d277e02
Track build script compile data through to rustc actions
UebelAndre 041c478
Skip known broken tests
UebelAndre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
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"], | ||
) |
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 |
---|---|---|
|
@@ -23,6 +23,7 @@ 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 | ||
|
@@ -198,6 +199,39 @@ 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. | ||
|
||
|
@@ -208,16 +242,35 @@ def _cargo_build_script_impl(ctx): | |
list: A list containing a BuildInfo provider | ||
""" | ||
script = ctx.executable.script | ||
script_info = ctx.attr.script[CargoBuildScriptRunfilesInfo] | ||
toolchain = find_toolchain(ctx) | ||
out_dir = ctx.actions.declare_directory(ctx.label.name + ".out_dir") | ||
env_out = ctx.actions.declare_file(ctx.label.name + ".env") | ||
dep_env_out = ctx.actions.declare_file(ctx.label.name + ".depenv") | ||
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 | ||
|
||
script_tools = [] | ||
script_data = [] | ||
for target in script_info.data: | ||
script_data.append(target[DefaultInfo].files) | ||
script_data.append(target[DefaultInfo].default_runfiles.files) | ||
for target in script_info.tools: | ||
script_tools.append(target[DefaultInfo].files) | ||
script_tools.append(target[DefaultInfo].default_runfiles.files) | ||
|
||
workspace_name = ctx.label.workspace_name | ||
if not workspace_name: | ||
workspace_name = ctx.workspace_name | ||
Comment on lines
+264
to
+266
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above, this can be simplified. |
||
|
||
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) | ||
script_data.append(depset([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"), | ||
|
@@ -331,8 +384,6 @@ def _cargo_build_script_impl(ctx): | |
variables = getattr(target[platform_common.TemplateVariableInfo], "variables", depset([])) | ||
env.update(variables) | ||
|
||
script_info = ctx.attr.script[CargoBuildScriptRunfilesInfo] | ||
|
||
_merge_env_dict(env, expand_dict_value_locations( | ||
ctx, | ||
ctx.attr.build_script_env, | ||
|
@@ -343,15 +394,6 @@ def _cargo_build_script_impl(ctx): | |
script_info.tools, | ||
)) | ||
|
||
script_tools = [] | ||
script_data = [] | ||
for target in script_info.data: | ||
script_data.append(target[DefaultInfo].files) | ||
script_data.append(target[DefaultInfo].default_runfiles.files) | ||
for target in script_info.tools: | ||
script_tools.append(target[DefaultInfo].files) | ||
script_tools.append(target[DefaultInfo].default_runfiles.files) | ||
|
||
tools = depset( | ||
direct = [ | ||
script, | ||
|
@@ -379,6 +421,7 @@ def _cargo_build_script_impl(ctx): | |
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 | ||
|
@@ -520,7 +563,12 @@ 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")), | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
External repos always fall into the
../
branch anyway.