Skip to content

Commit

Permalink
Add llvm-ir subtarget for rust rules
Browse files Browse the repository at this point in the history
Summary: This was useful in debugging S443733.

Reviewed By: dtolnay

Differential Revision: D62049233

fbshipit-source-id: c64d1f5b18fb1bb4c1d140c9bb60b1c427bac71c
  • Loading branch information
capickett authored and facebook-github-bot committed Aug 30, 2024
1 parent 8218782 commit fd82138
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
3 changes: 3 additions & 0 deletions prelude/rust/build.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,9 @@ def _explain(crate_type: CrateType, link_strategy: LinkStrategy, emit: Emit, inf
if emit == Emit("expand"):
return "expand"

if emit == Emit("llvm-ir"):
return "llvm-ir"

fail("unrecognized rustc action:", crate_type, link_strategy, emit)

EmitOperation = record(
Expand Down
21 changes: 11 additions & 10 deletions prelude/rust/rust_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -323,16 +323,17 @@ def _rust_binary_common(
incr_enabled = ctx.attrs.incremental_enabled
extra_compiled_targets.update(output_as_diag_subtargets(diag_artifacts[incr_enabled], clippy_artifacts[incr_enabled]))

expand = rust_compile(
ctx = ctx,
compile_ctx = compile_ctx,
emit = Emit("expand"),
params = strategy_param[DEFAULT_STATIC_LINK_STRATEGY],
default_roots = default_roots,
extra_flags = extra_flags,
incremental_enabled = ctx.attrs.incremental_enabled,
)
extra_compiled_targets["expand"] = expand.output
for emit in ("expand", "llvm-ir"):
compile = rust_compile(
ctx = ctx,
compile_ctx = compile_ctx,
emit = Emit(emit),
params = strategy_param[DEFAULT_STATIC_LINK_STRATEGY],
default_roots = default_roots,
extra_flags = extra_flags,
incremental_enabled = ctx.attrs.incremental_enabled,
)
extra_compiled_targets[emit] = compile.output

doc_output = generate_rustdoc(
ctx = ctx,
Expand Down
12 changes: 12 additions & 0 deletions prelude/rust/rust_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,15 @@ def rust_library_impl(ctx: AnalysisContext) -> list[Provider]:
incremental_enabled = ctx.attrs.incremental_enabled,
)

llvm_ir = rust_compile(
ctx = ctx,
compile_ctx = compile_ctx,
emit = Emit("llvm-ir"),
params = static_library_params,
default_roots = default_roots,
incremental_enabled = ctx.attrs.incremental_enabled,
)

# If doctests=True or False is set on the individual target, respect that.
# Otherwise look at the global setting on the toolchain.
doctests_enabled = \
Expand Down Expand Up @@ -308,6 +317,7 @@ def rust_library_impl(ctx: AnalysisContext) -> list[Provider]:
check_artifacts = output_as_diag_subtargets(diag_artifacts[incr_enabled], clippy_artifacts[incr_enabled]),
expand = expand.output,
sources = compile_ctx.symlinked_srcs,
llvm_ir = llvm_ir.output,
rustdoc_coverage = rustdoc_coverage,
named_deps_names = write_named_deps_names(ctx, compile_ctx),
)
Expand Down Expand Up @@ -519,6 +529,7 @@ def _default_providers(
check_artifacts: dict[str, Artifact | None],
expand: Artifact,
sources: Artifact,
llvm_ir: Artifact,
rustdoc_coverage: Artifact,
named_deps_names: Artifact | None) -> list[Provider]:
targets = {}
Expand All @@ -527,6 +538,7 @@ def _default_providers(
targets["expand"] = expand
targets["doc"] = rustdoc
targets["doc-coverage"] = rustdoc_coverage
targets["llvm-ir"] = llvm_ir
if named_deps_names:
targets["named_deps"] = named_deps_names
sub_targets = {
Expand Down

0 comments on commit fd82138

Please sign in to comment.