Skip to content
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
2 changes: 1 addition & 1 deletion doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ command line parameters file, those actions will be created here.
| :------------- | :------------- | :------------- |
| <a id="swift_common.create_linking_context_from_compilation_outputs-actions"></a>actions | The context's `actions` object. | none |
| <a id="swift_common.create_linking_context_from_compilation_outputs-additional_inputs"></a>additional_inputs | A `list` of `File`s containing any additional files that are referenced by `user_link_flags` and therefore need to be propagated up to the linker. | `[]` |
| <a id="swift_common.create_linking_context_from_compilation_outputs-alwayslink"></a>alwayslink | If `False`, any binary that depends on the providers returned by this function will link in all of the library's object files only if there are symbol references. See the discussion on `swift_library` `alwayslink` for why that behavior could result in undesired results. | `True` |
| <a id="swift_common.create_linking_context_from_compilation_outputs-alwayslink"></a>alwayslink | If `False`, any binary that depends on the providers returned by this function will link in all of the library's object files only if there are symbol references. See the discussion on `swift_library` `alwayslink` for why that behavior could result in undesired results. If `True`, the opposite will happen and this library will be -force_load into the link actions that depend on it. By default (`None`), the value of alwayslink will be set to `True` in the general case, and to `False` if the embedded swift feature is turned on. | `None` |
| <a id="swift_common.create_linking_context_from_compilation_outputs-compilation_outputs"></a>compilation_outputs | A `CcCompilationOutputs` value containing the object files to link. Typically, this is the second tuple element in the value returned by `compile`. | none |
| <a id="swift_common.create_linking_context_from_compilation_outputs-feature_configuration"></a>feature_configuration | A feature configuration obtained from `configure_features`. | none |
| <a id="swift_common.create_linking_context_from_compilation_outputs-is_test"></a>is_test | Deprecated. This argument will be removed in the next major release. Use the `include_dev_srch_paths` attribute instead. Represents if the `testonly` value of the context. | `None` |
Expand Down
6 changes: 3 additions & 3 deletions doc/rules.md

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion swift/internal/attrs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ and emit a `.swiftinterface` file as one of the compilation outputs.
mandatory = False,
),
"alwayslink": attr.bool(
default = True,
doc = """\
If `False`, any binary that depends (directly or indirectly) on this Swift module
will only link in all the object files for the files listed in `srcs` when there
Expand All @@ -318,7 +317,13 @@ get batched into a single `.o` by the compiler options used.
Swift Package Manager always passes the individual `.o` files to the linker
instead of using intermediate static libraries, so it effectively is the same
as `alwayslink = True`.

Note that by default, this value will default to True. But if the
swift.enable_embedded feature is on, this value will default to False, as
the swift features that cause -force_load to be required (such as reflection)
are not available in that mode.
""",
mandatory = False,
),
"generated_header_name": attr.string(
doc = """\
Expand Down
5 changes: 5 additions & 0 deletions swift/internal/compiling.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ load(
"SWIFT_FEATURE_EMIT_PRIVATE_SWIFTINTERFACE",
"SWIFT_FEATURE_EMIT_SWIFTDOC",
"SWIFT_FEATURE_EMIT_SWIFTINTERFACE",
"SWIFT_FEATURE_ENABLE_EMBEDDED",
"SWIFT_FEATURE_FULL_LTO",
"SWIFT_FEATURE_HEADERS_ALWAYS_ACTION_INPUTS",
"SWIFT_FEATURE_INDEX_WHILE_BUILDING",
Expand Down Expand Up @@ -1684,6 +1685,10 @@ def _emitted_output_nature(feature_configuration, user_compile_flags):
feature_configuration = feature_configuration,
feature_name = SWIFT_FEATURE__WMO_IN_SWIFTCOPTS,
) or
is_feature_enabled(
feature_configuration = feature_configuration,
feature_name = SWIFT_FEATURE_ENABLE_EMBEDDED,
) or
are_all_features_enabled(
feature_configuration = feature_configuration,
feature_names = [SWIFT_FEATURE_OPT, SWIFT_FEATURE_OPT_USES_WMO],
Expand Down
9 changes: 9 additions & 0 deletions swift/internal/feature_names.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -411,3 +411,12 @@ SWIFT_FEATURE_FULL_LTO = "swift.full_lto"
SWIFT_FEATURE_ENABLE_CPP17_INTEROP = "swift.enable_cpp17_interop"
SWIFT_FEATURE_ENABLE_CPP20_INTEROP = "swift.enable_cpp20_interop"
SWIFT_FEATURE_ENABLE_CPP23_INTEROP = "swift.enable_cpp23_interop"

# Enable embedded swift. More details at https://docs.swift.org/embedded/documentation/embedded/waystogetstarted/
# When enabling that option, a few things will happen:
# * WMO will be enabled automatically, otherwise the compiler will throw an error as it is a requirement for embedded swift
# * none of the libraries in the toolchain's usr/lib/swift directory will be linked. Instead, the core swift functionalities
# will be provided by the swift embedded module in the usr/lib/swift/embedded toolchain directory, and swiftc will
# automatically include it at compile time, and provide it to the linker at link time
# * alwayslink on swift_library() target will now default to False, as it is not required in embedded mode
SWIFT_FEATURE_ENABLE_EMBEDDED = "swift.enable_embedded"
15 changes: 13 additions & 2 deletions swift/internal/linking.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ load(
load(":developer_dirs.bzl", "developer_dirs_linkopts")
load(
":feature_names.bzl",
"SWIFT_FEATURE_ENABLE_EMBEDDED",
"SWIFT_FEATURE_LLD_GC_WORKAROUND",
"SWIFT_FEATURE_OBJC_LINK_FLAGS",
)
Expand Down Expand Up @@ -191,7 +192,7 @@ def create_linking_context_from_compilation_outputs(
*,
actions,
additional_inputs = [],
alwayslink = True,
alwayslink = None,
compilation_outputs,
feature_configuration,
is_test = None,
Expand Down Expand Up @@ -221,7 +222,11 @@ def create_linking_context_from_compilation_outputs(
returned by this function will link in all of the library's object
files only if there are symbol references. See the discussion on
`swift_library` `alwayslink` for why that behavior could result
in undesired results.
in undesired results. If `True`, the opposite will happen and this
library will be -force_load into the link actions that depend on it.
By default (`None`), the value of alwayslink will be set to `True`
in the general case, and to `False` if the embedded swift feature is
turned on.
compilation_outputs: A `CcCompilationOutputs` value containing the
object files to link. Typically, this is the second tuple element in
the value returned by `compile`.
Expand Down Expand Up @@ -322,6 +327,12 @@ def create_linking_context_from_compilation_outputs(
),
)

if alwayslink == None:
alwayslink = not is_feature_enabled(
feature_configuration = feature_configuration,
feature_name = SWIFT_FEATURE_ENABLE_EMBEDDED,
)

if include_dev_srch_paths != None and is_test != None:
fail("""\
Both `include_dev_srch_paths` and `is_test` cannot be specified. Please select \
Expand Down
15 changes: 15 additions & 0 deletions swift/toolchains/config/compile_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ load(
"SWIFT_FEATURE_ENABLE_CPP17_INTEROP",
"SWIFT_FEATURE_ENABLE_CPP20_INTEROP",
"SWIFT_FEATURE_ENABLE_CPP23_INTEROP",
"SWIFT_FEATURE_ENABLE_EMBEDDED",
"SWIFT_FEATURE_ENABLE_LIBRARY_EVOLUTION",
"SWIFT_FEATURE_ENABLE_SKIP_FUNCTION_BODIES",
"SWIFT_FEATURE_ENABLE_TESTING",
Expand Down Expand Up @@ -386,6 +387,7 @@ def compile_action_configs(
features = [
[SWIFT_FEATURE_OPT, SWIFT_FEATURE_OPT_USES_WMO],
[SWIFT_FEATURE__WMO_IN_SWIFTCOPTS],
[SWIFT_FEATURE_ENABLE_EMBEDDED],
],
),

Expand Down Expand Up @@ -1092,6 +1094,7 @@ def compile_action_configs(
not_features = [
[SWIFT_FEATURE_OPT, SWIFT_FEATURE_OPT_USES_WMO],
[SWIFT_FEATURE__WMO_IN_SWIFTCOPTS],
[SWIFT_FEATURE_ENABLE_EMBEDDED],
],
),

Expand All @@ -1112,6 +1115,7 @@ def compile_action_configs(
features = [
[SWIFT_FEATURE_OPT, SWIFT_FEATURE_OPT_USES_WMO],
[SWIFT_FEATURE__WMO_IN_SWIFTCOPTS],
[SWIFT_FEATURE_ENABLE_EMBEDDED],
],
not_features = [SWIFT_FEATURE__NUM_THREADS_0_IN_SWIFTCOPTS],
),
Expand Down Expand Up @@ -1337,6 +1341,17 @@ def compile_action_configs(
SWIFT_FEATURE_ENABLE_CPP23_INTEROP,
],
),
ActionConfigInfo(
actions = [
SWIFT_ACTION_COMPILE,
],
configurators = [
add_arg("-enable-experimental-feature", "Embedded"),
],
features = [
SWIFT_FEATURE_ENABLE_EMBEDDED,
],
),
]

# NOTE: The positions of these action configs in the list are important,
Expand Down
19 changes: 19 additions & 0 deletions test/features_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ disable_objc_test = make_action_command_line_test_rule(
},
)

embedded_test = make_action_command_line_test_rule(
config_settings = {
"//command_line_option:features": [
"swift.enable_embedded",
],
},
)

def features_test_suite(name, tags = []):
"""Test suite for various features.

Expand Down Expand Up @@ -324,6 +332,17 @@ def features_test_suite(name, tags = []):
],
)

embedded_test(
name = "{}_embedded_test".format(name),
tags = all_tags,
expected_argv = [
"-enable-experimental-feature",
"Embedded",
],
mnemonic = "SwiftCompile",
target_under_test = "//test/fixtures/basic:second",
)

native.test_suite(
name = name,
tags = all_tags,
Expand Down