Skip to content

Commit

Permalink
Add crate_info_dict attr
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinh Tran committed Oct 9, 2023
1 parent 4d8946b commit e43d2f2
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion proto/prost/private/prost.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def _compile_rust(ctx, attr, crate_name, src, deps, edition):
ctx = ctx,
attr = attr,
toolchain = toolchain,
crate_info = rust_common.create_crate_info(
crate_info_dict = dict(
name = crate_name,
type = "rlib",
root = src,
Expand Down
2 changes: 1 addition & 1 deletion proto/protobuf/proto.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def _rust_proto_compile(protos, descriptor_sets, imports, crate_name, ctx, is_gr
ctx = ctx,
attr = ctx.attr,
toolchain = toolchain,
crate_info = rust_common.create_crate_info(
crate_info_dict = dict(
name = crate_name,
type = "rlib",
root = lib_rs,
Expand Down
28 changes: 15 additions & 13 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,7 @@ def rustc_compile_action(
force_all_deps_direct = False,
rust_metadata = None,
output_file = None,
crate_info_dict = None,
skip_expanding_rustc_env = False):
"""Create and run a rustc compile action based on the current rule's attributes
Expand All @@ -1117,20 +1118,21 @@ def rustc_compile_action(
# TODO: Remove create_crate_info_callback after all rustc_compile_action callers migrate to
# removing CrateInfo construction before `rust_compile_action

crate_info_dict = None
if crate_info == None:
if ctx == None or toolchain == None or crate_type == None:
fail("FAIL", ctx, toolchain, crate_type)
crate_info_dict = create_crate_info_dict(
ctx = ctx,
toolchain = toolchain,
crate_type = crate_type,
rust_metadata = rust_metadata,
output_file = output_file,
)
# if crate_info == None:
# print(crate_info_dict)

if crate_info_dict != None:
crate_info = rust_common.create_crate_info(**crate_info_dict)
if crate_info == None:
if crate_info_dict:
crate_info = rust_common.create_crate_info(**crate_info_dict)
else:
crate_info_dict = create_crate_info_dict(
ctx = ctx,
toolchain = toolchain,
crate_type = crate_type,
rust_metadata = rust_metadata,
output_file = output_file,
)
crate_info = rust_common.create_crate_info(**crate_info_dict)

build_metadata = getattr(crate_info, "metadata", None)

Expand Down
2 changes: 1 addition & 1 deletion rust/private/utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ def _symlink_for_non_generated_source(ctx, src_file, package_root):
else:
return src_file

def create_crate_info_dict(ctx, toolchain, crate_type, rust_metadata, output_file):
def create_crate_info_dict(ctx, toolchain, crate_type, rust_metadata, output_file, crate_info_dict = None):
"""Creates a mutable dict() representing CrateInfo provider
create_crate_info_dict is a *temporary* solution until create_crate_info is completely moved into
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def _with_modified_crate_name_impl(ctx):
ctx = ctx,
attr = ctx.attr,
toolchain = toolchain,
crate_info = rust_common.create_crate_info(
crate_info_dict = dict(
name = crate_name,
type = crate_type,
root = crate_root,
Expand Down
2 changes: 1 addition & 1 deletion test/unit/force_all_deps_direct/generator.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ EOF
ctx = ctx,
attr = ctx.attr,
toolchain = toolchain,
crate_info = rust_common.create_crate_info(
crate_info_dict = dict(
name = crate_name,
type = crate_type,
root = rs_file,
Expand Down
2 changes: 1 addition & 1 deletion test/unit/pipelined_compilation/wrap.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ EOF
ctx = ctx,
attr = ctx.attr,
toolchain = toolchain,
crate_info = rust_common.create_crate_info(
crate_info_dict = dict(
name = crate_name,
type = crate_type,
root = rs_file,
Expand Down

0 comments on commit e43d2f2

Please sign in to comment.