Skip to content

Commit

Permalink
Expose a staticlib subtarget for rust libraries
Browse files Browse the repository at this point in the history
Summary:
Adds a `foo[staticlib]` subtarget to rust libraries, and uses it in `libclank`'s `staticlib_extractor`.

Ideally, the way that staticlib_extractor works to embed rust code into make requires a number of assumptions to hold, and we should try to fix this. The way zephyr_module works by gathering the link infos and exposing them as link args to cmake would be much nicer (https://www.internalfb.com/code/fbsource/[3616616e6817]/arvr/firmware/ar/zephyr/build_defs/zephyr_v2.bzl?lines=392-415)

Reviewed By: shayne-fletcher

Differential Revision: D57167468

fbshipit-source-id: 2bbbdbcfe86ef09c65a7a9a036dd2d68cd9f4a81
  • Loading branch information
capickett authored and facebook-github-bot committed May 10, 2024
1 parent 8b3fedd commit 4afbbd6
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions rust/rust_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ def rust_library_impl(ctx: AnalysisContext) -> list[Provider]:
check_artifacts = rust_param_artifact[check_params]
providers += _default_providers(
lang_style_param = lang_style_param,
param_artifact = rust_param_artifact,
rust_param_artifact = rust_param_artifact,
native_param_artifact = native_param_artifact,
rustdoc = rustdoc,
rustdoc_test = rustdoc_test,
doctests_enabled = doctests_enabled,
Expand Down Expand Up @@ -481,7 +482,8 @@ def _handle_rust_artifact(

def _default_providers(
lang_style_param: dict[(LinkageLang, LibOutputStyle), BuildParams],
param_artifact: dict[BuildParams, dict[MetadataKind, RustcOutput]],
rust_param_artifact: dict[BuildParams, dict[MetadataKind, RustcOutput]],
native_param_artifact: dict[BuildParams, RustcOutput],
rustdoc: Artifact,
rustdoc_test: cmd_args,
doctests_enabled: bool,
Expand All @@ -505,7 +507,7 @@ def _default_providers(
# determined by `get_output_styles_for_linkage` in `linking/link_info.bzl`.
# Do we want to do the same?
for output_style in LibOutputStyle:
link = param_artifact[lang_style_param[(LinkageLang("rust"), output_style)]][MetadataKind("link")]
link = rust_param_artifact[lang_style_param[(LinkageLang("rust"), output_style)]][MetadataKind("link")]
nested_sub_targets = {}
if link.pdb:
nested_sub_targets[PDB_SUB_TARGET] = get_pdb_providers(pdb = link.pdb, binary = link.output)
Expand All @@ -519,6 +521,13 @@ def _default_providers(
sub_targets = nested_sub_targets,
)]

lang_style_for_staticlib = (LinkageLang("native"), LibOutputStyle("archive"))
if lang_style_for_staticlib in lang_style_param:
artifact = native_param_artifact[lang_style_param[lang_style_for_staticlib]]
sub_targets["staticlib"] = [DefaultInfo(
default_output = artifact.output,
)]

providers = []

rustdoc_test_info = ExternalRunnerTestInfo(
Expand Down

0 comments on commit 4afbbd6

Please sign in to comment.