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

unix_cc_toolchain_config: macOS supports dynamic linker #23438

Closed

Conversation

malt3
Copy link
Contributor

@malt3 malt3 commented Aug 27, 2024

MacOS CC toolchains based on unix_cc_toolchain_config (such as the one provided by rules_nixpkgs) can no longer build dynamically linked cc_library targets on Bazel 7 and newer.
I traced the problem back to this check in the implementation of cc_library:

create_dynamic_library = (not ctx.attr.linkstatic and
                          supports_dynamic_linker and
                          (not cc_helper.is_compilation_outputs_empty(compilation_outputs) or
                           cc_common.is_enabled(
                               feature_configuration = feature_configuration,
                               feature_name = "header_module_codegen",
                           )))

For the auto-detected toolchain on macOS, the supports_dynamic_linker feature is set, and both a static and dynamic library can be built.
When using unix_cc_toolchain_config, we currently only get a static library.

As an aside, I noticed that the macOS feature list is a lot shorter. I think at least some of the other features could be added here:

--- /tmp/linux_features.txt     2024-08-27 14:27:14.037053585 +0200
+++ /tmp/macos_features.txt     2024-08-27 14:31:06.010876046 +0200
@@ -1,35 +1,10 @@
 features = [
             cpp_modules_feature,
+            macos_minimum_os_feature,
+            macos_default_link_flags_feature,
             dependency_file_feature,
-            serialized_diagnostics_file_feature,
-            random_seed_feature,
-            pic_feature,
-            per_object_debug_info_feature,
-            preprocessor_defines_feature,
-            includes_feature,
-            include_paths_feature,
-            external_include_paths_feature,
-            fdo_instrument_feature,
-            cs_fdo_instrument_feature,
-            cs_fdo_optimize_feature,
-            thinlto_feature,
-            fdo_prefetch_hints_feature,
-            autofdo_feature,
-            build_interface_libraries_feature,
-            dynamic_library_linker_tool_feature,
-            generate_linkmap_feature,
-            shared_flag_feature,
-            linkstamps_feature,
-            output_execpath_flags_feature,
-            runtime_library_search_directories_feature,
-            library_search_directories_feature,
             libtool_feature,
             archiver_flags_feature,
-            force_pic_flags_feature,
-            fission_support_feature,
-            strip_debug_symbols_feature,
-            coverage_feature,
-            supports_pic_feature,
             asan_feature,
             tsan_feature,
             ubsan_feature,
@@ -40,14 +15,13 @@
                 supports_start_end_lib_feature,
             ] if ctx.attr.supports_start_end_lib else []
         ) + [
+            coverage_feature,
             default_compile_flags_feature,
             default_link_flags_feature,
-            libraries_to_link_feature,
             user_link_flags_feature,
             default_link_libs_feature,
-            static_libgcc_feature,
+            external_include_paths_feature,
             fdo_optimize_feature,
-            supports_dynamic_linker_feature,
             dbg_feature,
             opt_feature,
             user_compile_flags_feature,
@@ -57,4 +31,5 @@
             unfiltered_compile_flags_feature,
             treat_warnings_as_errors_feature,
             archive_param_file_feature,
-        ] + layering_check_features(ctx.attr.compiler, ctx.attr.extra_flags_per_feature, is_macos = False)
+            generate_linkmap_feature,
+        ] + layering_check_features(ctx.attr.compiler, ctx.attr.extra_flags_per_feature, is_macos = True)

@github-actions github-actions bot added team-Rules-CPP Issues for C++ rules awaiting-review PR is awaiting review from an assigned reviewer labels Aug 27, 2024
malt3 added a commit to tweag/rules_nixpkgs that referenced this pull request Aug 27, 2024
malt3 added a commit to tweag/rules_nixpkgs that referenced this pull request Aug 27, 2024
@malt3
Copy link
Contributor Author

malt3 commented Aug 27, 2024

Looking at the test failures, I would assume that there are other related features missing. Does anyone understand the list of features well enough?

It looks like this was disabled on purpose.

bazelbuild/apple_support#326
ec55533

@malt3 malt3 marked this pull request as draft August 27, 2024 14:07
@malt3 malt3 closed this Aug 29, 2024
@malt3 malt3 deleted the feature/macos_supports_dynamic_linker branch August 29, 2024 08:49
@github-actions github-actions bot removed the awaiting-review PR is awaiting review from an assigned reviewer label Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Rules-CPP Issues for C++ rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant