Skip to content
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

Apply swift.add_target_name_to_output only to outputs that need it #1217

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ A tuple containing three elements:

<pre>
swift_common.compile_module_interface(<a href="#swift_common.compile_module_interface-actions">actions</a>, <a href="#swift_common.compile_module_interface-compilation_contexts">compilation_contexts</a>, <a href="#swift_common.compile_module_interface-feature_configuration">feature_configuration</a>,
<a href="#swift_common.compile_module_interface-module_name">module_name</a>, <a href="#swift_common.compile_module_interface-swiftinterface_file">swiftinterface_file</a>, <a href="#swift_common.compile_module_interface-swift_infos">swift_infos</a>, <a href="#swift_common.compile_module_interface-swift_toolchain">swift_toolchain</a>)
<a href="#swift_common.compile_module_interface-module_name">module_name</a>, <a href="#swift_common.compile_module_interface-swiftinterface_file">swiftinterface_file</a>, <a href="#swift_common.compile_module_interface-swift_infos">swift_infos</a>, <a href="#swift_common.compile_module_interface-swift_toolchain">swift_toolchain</a>,
<a href="#swift_common.compile_module_interface-target_name">target_name</a>)
</pre>

Compiles a Swift module interface.
Expand All @@ -168,6 +169,7 @@ Compiles a Swift module interface.
| <a id="swift_common.compile_module_interface-swiftinterface_file"></a>swiftinterface_file | The Swift module interface file to compile. | none |
| <a id="swift_common.compile_module_interface-swift_infos"></a>swift_infos | A list of `SwiftInfo` providers from dependencies of the target being compiled. | none |
| <a id="swift_common.compile_module_interface-swift_toolchain"></a>swift_toolchain | The `SwiftToolchainInfo` provider of the toolchain. | none |
| <a id="swift_common.compile_module_interface-target_name"></a>target_name | The name of the target for which the code is being compiled, which is used to determine unique file paths for the outputs. | none |

**RETURNS**

Expand Down
40 changes: 7 additions & 33 deletions swift/internal/compiling.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2179,7 +2179,8 @@ def compile_module_interface(
module_name,
swiftinterface_file,
swift_infos,
swift_toolchain):
swift_toolchain,
target_name):
"""Compiles a Swift module interface.

Args:
Expand All @@ -2198,6 +2199,9 @@ def compile_module_interface(
swift_infos: A list of `SwiftInfo` providers from dependencies of the
target being compiled.
swift_toolchain: The `SwiftToolchainInfo` provider of the toolchain.
target_name: The name of the target for which the code is being
compiled, which is used to determine unique file paths for the
outputs.

Returns:
A Swift module context (as returned by `swift_common.create_module`)
Expand Down Expand Up @@ -2235,11 +2239,6 @@ def compile_module_interface(
continue
transitive_swiftmodules.append(swift_module.swiftmodule)

add_target_name_to_output_path = is_feature_enabled(
feature_configuration = feature_configuration,
feature_name = SWIFT_FEATURE_ADD_TARGET_NAME_TO_OUTPUT,
)

# We need this when generating the VFS overlay file and also when
# configuring inputs for the compile action, so it's best to precompute it
# here.
Expand All @@ -2249,8 +2248,7 @@ def compile_module_interface(
):
vfsoverlay_file = derived_files.vfsoverlay(
actions = actions,
add_target_name_to_output_path = add_target_name_to_output_path,
target_name = module_name,
target_name = target_name,
)
write_vfsoverlay(
actions = actions,
Expand All @@ -2269,7 +2267,7 @@ def compile_module_interface(
fail("Cannot use both `swift.vfsoverlay` and `swift.use_explicit_swift_module_map` features at the same time.")

explicit_swift_module_map_file = actions.declare_file(
"{}.swift-explicit-module-map.json".format(module_name),
"{}.swift-explicit-module-map.json".format(target_name),
)
write_explicit_swift_module_map_file(
actions = actions,
Expand Down Expand Up @@ -2545,11 +2543,6 @@ def compile(
sets.make(swift_module.defines),
)

add_target_name_to_output_path = is_feature_enabled(
feature_configuration = feature_configuration,
feature_name = SWIFT_FEATURE_ADD_TARGET_NAME_TO_OUTPUT,
)

# We need this when generating the VFS overlay file and also when
# configuring inputs for the compile action, so it's best to precompute it
# here.
Expand All @@ -2559,7 +2552,6 @@ def compile(
):
vfsoverlay_file = derived_files.vfsoverlay(
actions = actions,
add_target_name_to_output_path = add_target_name_to_output_path,
target_name = target_name,
)
write_vfsoverlay(
Expand Down Expand Up @@ -2887,14 +2879,8 @@ def _precompile_clang_module(
):
return None

add_target_name_to_output_path = is_feature_enabled(
feature_configuration = feature_configuration,
feature_name = SWIFT_FEATURE_ADD_TARGET_NAME_TO_OUTPUT,
)

precompiled_module = derived_files.precompiled_module(
actions = actions,
add_target_name_to_output_path = add_target_name_to_output_path,
target_name = target_name,
)

Expand Down Expand Up @@ -3216,12 +3202,10 @@ def _declare_compile_outputs(
# no other partial outputs.
object_files = [derived_files.whole_module_object_file(
actions = actions,
add_target_name_to_output_path = add_target_name_to_output_path,
target_name = target_name,
)]
ast_files = [derived_files.ast(
actions = actions,
add_target_name_to_output_path = add_target_name_to_output_path,
target_name = target_name,
src = srcs[0],
)]
Expand All @@ -3242,7 +3226,6 @@ def _declare_compile_outputs(
# object files so that we can pass them all to the archive action.
output_info = _declare_multiple_outputs_and_write_output_file_map(
actions = actions,
add_target_name_to_output_path = add_target_name_to_output_path,
extract_const_values = extract_const_values,
is_wmo = output_nature.is_wmo,
emits_bc = emits_bc,
Expand Down Expand Up @@ -3270,7 +3253,6 @@ def _declare_compile_outputs(
):
indexstore_directory = derived_files.indexstore_directory(
actions = actions,
add_target_name_to_output_path = add_target_name_to_output_path,
target_name = target_name,
)
else:
Expand All @@ -3283,7 +3265,6 @@ def _declare_compile_outputs(
if (emit_symbol_graph):
symbol_graph_directory = derived_files.symbol_graph_directory(
actions = actions,
add_target_name_to_output_path = add_target_name_to_output_path,
target_name = target_name,
)
else:
Expand Down Expand Up @@ -3323,7 +3304,6 @@ def _declare_compile_outputs(

def _declare_multiple_outputs_and_write_output_file_map(
actions,
add_target_name_to_output_path,
extract_const_values,
is_wmo,
emits_bc,
Expand All @@ -3334,7 +3314,6 @@ def _declare_multiple_outputs_and_write_output_file_map(

Args:
actions: The object used to register actions.
add_target_name_to_output_path: Add target_name in output path. More info at SWIFT_FEATURE_ADD_TARGET_NAME_TO_OUTPUT description.
extract_const_values: A Boolean value indicating whether constant values
should be extracted during this compilation.
is_wmo: A Boolean value indicating whether whole-module-optimization was
Expand Down Expand Up @@ -3366,14 +3345,12 @@ def _declare_multiple_outputs_and_write_output_file_map(
"""
output_map_file = derived_files.swiftc_output_file_map(
actions = actions,
add_target_name_to_output_path = add_target_name_to_output_path,
target_name = target_name,
)

if split_derived_file_generation:
derived_files_output_map_file = derived_files.swiftc_derived_output_file_map(
actions = actions,
add_target_name_to_output_path = add_target_name_to_output_path,
target_name = target_name,
)
else:
Expand Down Expand Up @@ -3420,7 +3397,6 @@ def _declare_multiple_outputs_and_write_output_file_map(
# Declare the llvm bc file (there is one per source file).
obj = derived_files.intermediate_bc_file(
actions = actions,
add_target_name_to_output_path = add_target_name_to_output_path,
target_name = target_name,
src = src,
)
Expand All @@ -3430,7 +3406,6 @@ def _declare_multiple_outputs_and_write_output_file_map(
# Declare the object file (there is one per source file).
obj = derived_files.intermediate_object_file(
actions = actions,
add_target_name_to_output_path = add_target_name_to_output_path,
target_name = target_name,
src = src,
)
Expand All @@ -3439,7 +3414,6 @@ def _declare_multiple_outputs_and_write_output_file_map(

ast = derived_files.ast(
actions = actions,
add_target_name_to_output_path = add_target_name_to_output_path,
target_name = target_name,
src = src,
)
Expand Down
7 changes: 0 additions & 7 deletions swift/internal/debugging.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ load(
load(":derived_files.bzl", "derived_files")
load(
":feature_names.bzl",
"SWIFT_FEATURE_ADD_TARGET_NAME_TO_OUTPUT",
"SWIFT_FEATURE_DBG",
"SWIFT_FEATURE_FASTBUILD",
"SWIFT_FEATURE_NO_EMBED_DEBUG_MODULE",
Expand Down Expand Up @@ -59,17 +58,11 @@ def ensure_swiftmodule_is_embedded(
action_name = swift_action_names.MODULEWRAP,
swift_toolchain = swift_toolchain,
):
add_target_name_to_output_path = is_feature_enabled(
feature_configuration = feature_configuration,
feature_name = SWIFT_FEATURE_ADD_TARGET_NAME_TO_OUTPUT,
)

# For ELF-format binaries, we need to invoke a Swift modulewrap action
# to wrap the .swiftmodule file in a .o file that gets propagated to the
# linker.
modulewrap_obj = derived_files.modulewrap_object(
actions,
add_target_name_to_output_path = add_target_name_to_output_path,
target_name = label.name,
)
_register_modulewrap_action(
Expand Down
Loading