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

Add emit_bc feature #2

Open
wants to merge 2 commits into
base: uber/ios/0.15.0.002
Choose a base branch
from
Open
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
18 changes: 17 additions & 1 deletion swift/internal/compiling.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ load(
"SWIFT_FEATURE_USE_GLOBAL_MODULE_CACHE",
"SWIFT_FEATURE_VFSOVERLAY",
"SWIFT_FEATURE_SPLIT_DERIVED_FILES_GENERATION",
"SWIFT_FEATURE_EMIT_BC",
)
load(":features.bzl", "are_all_features_enabled", "is_feature_enabled")
load(":providers.bzl", "SwiftInfo", "create_swift_info")
Expand Down Expand Up @@ -93,11 +94,21 @@ def compile_action_configs():
# Emit object file(s).
swift_toolchain_config.action_config(
actions = [swift_action_names.COMPILE],
not_features = [SWIFT_FEATURE_EMIT_BC],
configurators = [
swift_toolchain_config.add_arg("-emit-object"),
],
),

# Emit bitcode file
swift_toolchain_config.action_config(
actions = [swift_action_names.COMPILE],
features = [SWIFT_FEATURE_EMIT_BC],
configurators = [
swift_toolchain_config.add_arg("-emit-bc"),
],
),

# Add the single object file or object file map, whichever is needed.
swift_toolchain_config.action_config(
actions = [swift_action_names.COMPILE],
Expand Down Expand Up @@ -1567,10 +1578,15 @@ def _declare_compile_outputs(
user_compile_flags = user_compile_flags,
)

if not output_nature.emits_multiple_objects:
emit_bc = is_feature_enabled(
feature_configuration = feature_configuration,
feature_name = SWIFT_FEATURE_EMIT_BC,
)
if not output_nature.emits_multiple_objects or emit_bc:
# If we're emitting a single object, we don't use an object map; we just
# declare the output file that the compiler will generate and there are
# no other partial outputs.
# If emit_bc is on, only one bitcode file is emitted
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tried output-file-map, it doesn't seem to work with emic_bc, -### revealed it just ignore the output option and default to module-name.bc

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

even with num-threads set? curious.

Copy link
Collaborator Author

@ghvg1313 ghvg1313 Jul 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I'm missing something here

  • with num-threads on, swift will actually try to output multiple bc files, except that I can't find an option to control the output location, whatever client option I provide it just ignores it and output to the root
  • with single threaded wmo, it will behave like buck did, this seems intentional, I'm just gonna disable threading during bc_merge pipeline I think

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you say root what do you mean?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bazel exec root
so swiftc -emit-bc -wmo -num-threads 6 -output-file-map output.json a.swift b.swift-### will get you swiftc- frontend -emit-bc ... a.bc b.bc
Doesn't matter what you put in output.json

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. Pretty fine with the single object file output if that makes things easier.

object_files = [derived_files.whole_module_object_file(
actions = actions,
target_name = target_name,
Expand Down
4 changes: 4 additions & 0 deletions swift/internal/feature_names.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,7 @@ SWIFT_FEATURE_SUPPORTS_PRIVATE_DEPS = "swift.supports_private_deps"
# `*.swiftmodule` and `*-Swift.h` are generated with a separate action
# rather than as part of the compilation.
SWIFT_FEATURE_SPLIT_DERIVED_FILES_GENERATION = "swift.split_derived_files_generation"

# If enabled, Swift compilation will produce LLVM bitcode instead of object file
# the output will share the same name as the object file (file.o)
SWIFT_FEATURE_EMIT_BC = "swift.emit_bc"