diff options
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionConfigs.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionConfigs.java | 123 |
1 files changed, 59 insertions, 64 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionConfigs.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionConfigs.java index dc7b250c0a..6eba06d0f7 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionConfigs.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionConfigs.java @@ -62,10 +62,9 @@ public class CppLinkActionConfigs { " implies: 'symbol_counts'", " implies: 'linkstamps'", " implies: 'output_execpath_flags_executable'", - " implies: 'global_whole_archive_open'", " implies: 'runtime_root_flags'", " implies: 'input_param_flags'", - " implies: 'global_whole_archive_close'", + " implies: 'libraries_to_link'", " implies: 'force_pic_flags'", "}", "action_config {", @@ -80,10 +79,9 @@ public class CppLinkActionConfigs { " implies: 'shared_flag'", " implies: 'linkstamps'", " implies: 'output_execpath_flags'", - " implies: 'global_whole_archive_open'", " implies: 'runtime_root_flags'", " implies: 'input_param_flags'", - " implies: 'global_whole_archive_close'", + " implies: 'libraries_to_link'", "}", "action_config {", " config_name: 'c++-link-static-library'", @@ -91,10 +89,9 @@ public class CppLinkActionConfigs { " tool {", " tool_path: 'DUMMY_TOOL'", " }", - " implies: 'global_whole_archive_open'", " implies: 'runtime_root_flags'", " implies: 'input_param_flags'", - " implies: 'global_whole_archive_close'", + " implies: 'libraries_to_link'", "}", "action_config {", " config_name: 'c++-link-alwayslink-static-library'", @@ -102,10 +99,9 @@ public class CppLinkActionConfigs { " tool {", " tool_path: 'DUMMY_TOOL'", " }", - " implies: 'global_whole_archive_open'", " implies: 'runtime_root_flags'", " implies: 'input_param_flags'", - " implies: 'global_whole_archive_close'", + " implies: 'libraries_to_link'", "}", "action_config {", " config_name: 'c++-link-pic-static-library'", @@ -113,10 +109,9 @@ public class CppLinkActionConfigs { " tool {", " tool_path: 'DUMMY_TOOL'", " }", - " implies: 'global_whole_archive_open'", " implies: 'runtime_root_flags'", " implies: 'input_param_flags'", - " implies: 'global_whole_archive_close'", + " implies: 'libraries_to_link'", "}", "action_config {", " config_name: 'c++-link-alwayslink-pic-static-library'", @@ -124,10 +119,9 @@ public class CppLinkActionConfigs { " tool {", " tool_path: 'DUMMY_TOOL'", " }", - " implies: 'global_whole_archive_open'", " implies: 'runtime_root_flags'", " implies: 'input_param_flags'", - " implies: 'global_whole_archive_close'", + " implies: 'libraries_to_link'", "}", "feature {", " name: 'build_interface_libraries'", @@ -215,24 +209,6 @@ public class CppLinkActionConfigs { " }", "}", "feature {", - " name: 'global_whole_archive_open'", - " flag_set {", - " expand_if_all_available: 'global_whole_archive'", - " action: 'c++-link-executable'", - " action: 'c++-link-dynamic-library'", - " action: 'c++-link-static-library'", - " action: 'c++-link-alwayslink-static-library'", - " action: 'c++-link-pic-static-library'", - " action: 'c++-link-alwayslink-pic-static-library'", - " flag_group {", - // TODO: Factor platform difference into respective linux and OSX crosstools. - String.format( - " flag:'%s'", - platform == CppLinkPlatform.LINUX ? "-Wl,-whole-archive" : "-Wl,-all_load"), - " }", - " }", - "}", - "feature {", " name: 'runtime_root_flags',", " flag_set {", " expand_if_all_available: 'runtime_root_flags'", @@ -273,39 +249,11 @@ public class CppLinkActionConfigs { " flag: '%{libopts}'", " }", " }", - " flag_set {", - " expand_if_all_available: 'whole_archive_linker_params'", - " action: 'c++-link-executable'", - " action: 'c++-link-dynamic-library'", - " action: 'c++-link-static-library'", - " action: 'c++-link-alwayslink-static-library'", - " action: 'c++-link-pic-static-library'", - " action: 'c++-link-alwayslink-pic-static-library'", - " flag_group {", - platform == CppLinkPlatform.LINUX - ? " flag: '-Wl,-whole-archive'\n" - + " flag: '%{whole_archive_linker_params}'\n" - + " flag: '-Wl,-no-whole-archive'" - : " flag: '-Wl,-force_load,%{whole_archive_linker_params}'", - " }", - " }", - " flag_set {", - " expand_if_all_available: 'linker_input_params'", - " action: 'c++-link-executable'", - " action: 'c++-link-dynamic-library'", - " action: 'c++-link-static-library'", - " action: 'c++-link-alwayslink-static-library'", - " action: 'c++-link-pic-static-library'", - " action: 'c++-link-alwayslink-pic-static-library'", - " flag_group {", - " flag: '%{linker_input_params}'", - " }", - " }", "}", "feature {", - " name: 'global_whole_archive_close'", + " name: 'libraries_to_link'", " flag_set {", - " expand_if_all_available: 'global_whole_archive'", + " expand_if_all_available: 'libraries_to_link'", " action: 'c++-link-executable'", " action: 'c++-link-dynamic-library'", " action: 'c++-link-static-library'", @@ -313,10 +261,41 @@ public class CppLinkActionConfigs { " action: 'c++-link-pic-static-library'", " action: 'c++-link-alwayslink-pic-static-library'", " flag_group {", - // TODO: Factor platform difference into respective linux and OSX crosstools. - String.format( - " flag: '%s'", - platform == CppLinkPlatform.LINUX ? "-Wl,-no-whole-archive" : ""), + " iterate_over: 'libraries_to_link'", + " flag_group {", + " expand_if_true: 'libraries_to_link.is_lib_group'", + " flag: '-Wl,--start-lib'", + " }", + ifLinux( + platform, + " flag_group {", + " expand_if_true: 'libraries_to_link.is_whole_archive'", + " flag: '-Wl,-whole-archive'", + " }", + " flag_group {", + " iterate_over: 'libraries_to_link.names'", + " flag: '%{libraries_to_link.names}'", + " }", + " flag_group {", + " expand_if_true: 'libraries_to_link.is_whole_archive'", + " flag: '-Wl,-no-whole-archive'", + " }"), + ifMac( + platform, + " flag_group {", + " expand_if_true: 'libraries_to_link.is_whole_archive'", + " iterate_over: 'libraries_to_link.names'", + " flag: '-Wl,-force_load,%{libraries_to_link.names}'", + " }", + " flag_group {", + " expand_if_false: 'libraries_to_link.is_whole_archive'", + " iterate_over: 'libraries_to_link.names'", + " flag: '%{libraries_to_link.names}'", + " }"), + " flag_group {", + " expand_if_true: 'libraries_to_link.is_lib_group'", + " flag: '-Wl,--end-lib'", + " }", " }", " }", "}", @@ -331,4 +310,20 @@ public class CppLinkActionConfigs { " }", "}")); } + + private static String ifLinux(CppLinkPlatform platform, String... lines) { + if (platform == CppLinkPlatform.LINUX) { + return Joiner.on("\n").join(lines); + } else { + return ""; + } + } + + private static String ifMac(CppLinkPlatform platform, String... lines) { + if (platform == CppLinkPlatform.MAC) { + return Joiner.on("\n").join(lines); + } else { + return ""; + } + } } |