From 2a5a528601e70df46fb3f13c2cc982c86c51fde8 Mon Sep 17 00:00:00 2001 From: Aaron Michaux Date: Thu, 12 Sep 2024 11:15:14 -0400 Subject: [PATCH 1/7] initial fix for #1271, set_file_prefix_map attribute --- foreign_cc/cmake.bzl | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/foreign_cc/cmake.bzl b/foreign_cc/cmake.bzl index cfe03dc19..1278772ac 100644 --- a/foreign_cc/cmake.bzl +++ b/foreign_cc/cmake.bzl @@ -184,6 +184,7 @@ def _cmake_impl(ctx): create_configure_script = _create_configure_script, tools_data = tools_data, cmake_path = cmake_data.path, + set_file_prefix_map = ctx.attr.set_file_prefix_map, ) return cc_external_rule_impl(ctx, attrs) @@ -203,6 +204,10 @@ def _create_configure_script(configureParameters): flags = get_flags_info(ctx, "") no_toolchain_file = ctx.attr.cache_entries.get("CMAKE_TOOLCHAIN_FILE") or not ctx.attr.generate_crosstool_file + if attrs.set_file_prefix_map: + flags.cc.append("-ffile-prefix-map=$EXT_BUILD_ROOT=.") + flags.cxx.append("-ffile-prefix-map=$EXT_BUILD_ROOT=.") + cmake_commands = [] configuration = "Debug" if is_debug_mode(ctx) else "Release" @@ -401,6 +406,14 @@ def _attrs(): mandatory = False, default = "", ), + "set_file_prefix_map": attr.bool( + doc = ( + "Use -ffile-prefix-map with the intention to remove the sandbox path from " +\ + "debug symbols" + ), + mandatory = False, + default = False + ), }) return attrs From 4c794b8a8b4320167e35cb315c78b84f3b6a6fdc Mon Sep 17 00:00:00 2001 From: Aaron Michaux Date: Thu, 12 Sep 2024 11:23:40 -0400 Subject: [PATCH 2/7] buildifiered --- foreign_cc/cmake.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/foreign_cc/cmake.bzl b/foreign_cc/cmake.bzl index 1278772ac..9993a5a98 100644 --- a/foreign_cc/cmake.bzl +++ b/foreign_cc/cmake.bzl @@ -408,11 +408,11 @@ def _attrs(): ), "set_file_prefix_map": attr.bool( doc = ( - "Use -ffile-prefix-map with the intention to remove the sandbox path from " +\ + "Use -ffile-prefix-map with the intention to remove the sandbox path from " + "debug symbols" ), mandatory = False, - default = False + default = False, ), }) return attrs From fab1f93bb0c05ccdb76cb962d65a2f3a974cbab0 Mon Sep 17 00:00:00 2001 From: Aaron Michaux Date: Thu, 12 Sep 2024 11:40:35 -0400 Subject: [PATCH 3/7] moved logic in cmake, make, meson, and ninja --- foreign_cc/cmake.bzl | 5 ----- foreign_cc/make.bzl | 8 ++++++++ foreign_cc/meson.bzl | 8 ++++++++ foreign_cc/ninja.bzl | 8 ++++++++ foreign_cc/private/cc_toolchain_util.bzl | 5 +++++ 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/foreign_cc/cmake.bzl b/foreign_cc/cmake.bzl index 9993a5a98..589fceeec 100644 --- a/foreign_cc/cmake.bzl +++ b/foreign_cc/cmake.bzl @@ -184,7 +184,6 @@ def _cmake_impl(ctx): create_configure_script = _create_configure_script, tools_data = tools_data, cmake_path = cmake_data.path, - set_file_prefix_map = ctx.attr.set_file_prefix_map, ) return cc_external_rule_impl(ctx, attrs) @@ -204,10 +203,6 @@ def _create_configure_script(configureParameters): flags = get_flags_info(ctx, "") no_toolchain_file = ctx.attr.cache_entries.get("CMAKE_TOOLCHAIN_FILE") or not ctx.attr.generate_crosstool_file - if attrs.set_file_prefix_map: - flags.cc.append("-ffile-prefix-map=$EXT_BUILD_ROOT=.") - flags.cxx.append("-ffile-prefix-map=$EXT_BUILD_ROOT=.") - cmake_commands = [] configuration = "Debug" if is_debug_mode(ctx) else "Release" diff --git a/foreign_cc/make.bzl b/foreign_cc/make.bzl index fcdd8a5cf..a5e0a0d18 100644 --- a/foreign_cc/make.bzl +++ b/foreign_cc/make.bzl @@ -101,6 +101,14 @@ def _attrs(): mandatory = False, default = ["", "install"], ), + "set_file_prefix_map": attr.bool( + doc = ( + "Use -ffile-prefix-map with the intention to remove the sandbox path from " + + "debug symbols" + ), + mandatory = False, + default = False, + ), }) return attrs diff --git a/foreign_cc/meson.bzl b/foreign_cc/meson.bzl index 9d4179ab2..b2faccb1f 100644 --- a/foreign_cc/meson.bzl +++ b/foreign_cc/meson.bzl @@ -178,6 +178,14 @@ def _attrs(): doc = "Arguments for the Meson setup command", mandatory = False, ), + "set_file_prefix_map": attr.bool( + doc = ( + "Use -ffile-prefix-map with the intention to remove the sandbox path from " + + "debug symbols" + ), + mandatory = False, + default = False, + ), }) return attrs diff --git a/foreign_cc/ninja.bzl b/foreign_cc/ninja.bzl index 9b872e622..f3266affc 100644 --- a/foreign_cc/ninja.bzl +++ b/foreign_cc/ninja.bzl @@ -101,6 +101,14 @@ def _attrs(): "directory of the `lib_sources` attribute if this attribute is not set" ), ), + "set_file_prefix_map": attr.bool( + doc = ( + "Use -ffile-prefix-map with the intention to remove the sandbox path from " + + "debug symbols" + ), + mandatory = False, + default = False, + ), }) return attrs diff --git a/foreign_cc/private/cc_toolchain_util.bzl b/foreign_cc/private/cc_toolchain_util.bzl index 9b3397475..3c0e9bcb3 100644 --- a/foreign_cc/private/cc_toolchain_util.bzl +++ b/foreign_cc/private/cc_toolchain_util.bzl @@ -306,6 +306,11 @@ def get_flags_info(ctx, link_output_file = None): ), ), ) + + if ctx.attr.set_file_prefix_map: + copts.append("-ffile-prefix-map=$EXT_BUILD_ROOT=.") + cxxopts.append("-ffile-prefix-map=$EXT_BUILD_ROOT=.") + return CxxFlagsInfo( cc = _convert_flags(cc_toolchain_.compiler, _add_if_needed(flags.cc, copts)), cxx = _convert_flags(cc_toolchain_.compiler, _add_if_needed(flags.cxx, cxxopts)), From 0065f695e9c1ddfa3b7cb45c40d8db01457ecd50 Mon Sep 17 00:00:00 2001 From: Aaron Michaux Date: Thu, 12 Sep 2024 11:49:11 -0400 Subject: [PATCH 4/7] fix for when attr not set --- foreign_cc/private/cc_toolchain_util.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/foreign_cc/private/cc_toolchain_util.bzl b/foreign_cc/private/cc_toolchain_util.bzl index 3c0e9bcb3..3b15578e0 100644 --- a/foreign_cc/private/cc_toolchain_util.bzl +++ b/foreign_cc/private/cc_toolchain_util.bzl @@ -307,7 +307,7 @@ def get_flags_info(ctx, link_output_file = None): ), ) - if ctx.attr.set_file_prefix_map: + if "set_file_prefix_map" in dir(ctx.attr) and ctx.attr.set_file_prefix_map: copts.append("-ffile-prefix-map=$EXT_BUILD_ROOT=.") cxxopts.append("-ffile-prefix-map=$EXT_BUILD_ROOT=.") From 60472c49e580815f8ec47dedb40a2cc6a9cc1416 Mon Sep 17 00:00:00 2001 From: Aaron Michaux Date: Thu, 12 Sep 2024 11:53:06 -0400 Subject: [PATCH 5/7] sorting dictionary entries to appease buildifier --- foreign_cc/cmake.bzl | 16 ++++++++-------- foreign_cc/make.bzl | 16 ++++++++-------- foreign_cc/meson.bzl | 8 ++++---- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/foreign_cc/cmake.bzl b/foreign_cc/cmake.bzl index 589fceeec..8972a3d48 100644 --- a/foreign_cc/cmake.bzl +++ b/foreign_cc/cmake.bzl @@ -393,14 +393,6 @@ def _attrs(): doc = "Arguments for the CMake install command", mandatory = False, ), - "working_directory": attr.string( - doc = ( - "Working directory, with the main CMakeLists.txt " + - "(otherwise, the top directory of the lib_source label files is used.)" - ), - mandatory = False, - default = "", - ), "set_file_prefix_map": attr.bool( doc = ( "Use -ffile-prefix-map with the intention to remove the sandbox path from " + @@ -409,6 +401,14 @@ def _attrs(): mandatory = False, default = False, ), + "working_directory": attr.string( + doc = ( + "Working directory, with the main CMakeLists.txt " + + "(otherwise, the top directory of the lib_source label files is used.)" + ), + mandatory = False, + default = "", + ), }) return attrs diff --git a/foreign_cc/make.bzl b/foreign_cc/make.bzl index a5e0a0d18..6578a6f84 100644 --- a/foreign_cc/make.bzl +++ b/foreign_cc/make.bzl @@ -91,6 +91,14 @@ def _attrs(): mandatory = False, default = "$$INSTALLDIR$$", ), + "set_file_prefix_map": attr.bool( + doc = ( + "Use -ffile-prefix-map with the intention to remove the sandbox path from " + + "debug symbols" + ), + mandatory = False, + default = False, + ), "targets": attr.string_list( doc = ( "A list of targets within the foreign build system to produce. An empty string (`\"\"`) will result in " + @@ -101,14 +109,6 @@ def _attrs(): mandatory = False, default = ["", "install"], ), - "set_file_prefix_map": attr.bool( - doc = ( - "Use -ffile-prefix-map with the intention to remove the sandbox path from " + - "debug symbols" - ), - mandatory = False, - default = False, - ), }) return attrs diff --git a/foreign_cc/meson.bzl b/foreign_cc/meson.bzl index b2faccb1f..8b057d02b 100644 --- a/foreign_cc/meson.bzl +++ b/foreign_cc/meson.bzl @@ -174,10 +174,6 @@ def _attrs(): mandatory = False, default = {}, ), - "setup_args": attr.string_list( - doc = "Arguments for the Meson setup command", - mandatory = False, - ), "set_file_prefix_map": attr.bool( doc = ( "Use -ffile-prefix-map with the intention to remove the sandbox path from " + @@ -186,6 +182,10 @@ def _attrs(): mandatory = False, default = False, ), + "setup_args": attr.string_list( + doc = "Arguments for the Meson setup command", + mandatory = False, + ), }) return attrs From 6ee44fefa5e784a4ce777c1dae2a5a61002d819c Mon Sep 17 00:00:00 2001 From: Aaron Michaux Date: Thu, 12 Sep 2024 13:09:42 -0400 Subject: [PATCH 6/7] added logic to make_configure --- foreign_cc/configure.bzl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/foreign_cc/configure.bzl b/foreign_cc/configure.bzl index d0f50d156..c01a84517 100644 --- a/foreign_cc/configure.bzl +++ b/foreign_cc/configure.bzl @@ -212,6 +212,14 @@ def _attrs(): mandatory = False, default = "--prefix=", ), + "set_file_prefix_map": attr.bool( + doc = ( + "Use -ffile-prefix-map with the intention to remove the sandbox path from " + + "debug symbols" + ), + mandatory = False, + default = False, + ), "targets": attr.string_list( doc = ( "A list of targets within the foreign build system to produce. An empty string (`\"\"`) will result in " + From 32750dbd478995cb2e36e96a29aa69de90f559e4 Mon Sep 17 00:00:00 2001 From: Aaron Michaux Date: Thu, 19 Sep 2024 09:31:30 -0400 Subject: [PATCH 7/7] Moved set_file_prefix_map attribute rule into CC_EXTERNAL_RULE_ATTRIBUTES --- foreign_cc/cmake.bzl | 8 -------- foreign_cc/configure.bzl | 8 -------- foreign_cc/make.bzl | 8 -------- foreign_cc/meson.bzl | 8 -------- foreign_cc/ninja.bzl | 8 -------- foreign_cc/private/framework.bzl | 8 ++++++++ 6 files changed, 8 insertions(+), 40 deletions(-) diff --git a/foreign_cc/cmake.bzl b/foreign_cc/cmake.bzl index 8972a3d48..cfe03dc19 100644 --- a/foreign_cc/cmake.bzl +++ b/foreign_cc/cmake.bzl @@ -393,14 +393,6 @@ def _attrs(): doc = "Arguments for the CMake install command", mandatory = False, ), - "set_file_prefix_map": attr.bool( - doc = ( - "Use -ffile-prefix-map with the intention to remove the sandbox path from " + - "debug symbols" - ), - mandatory = False, - default = False, - ), "working_directory": attr.string( doc = ( "Working directory, with the main CMakeLists.txt " + diff --git a/foreign_cc/configure.bzl b/foreign_cc/configure.bzl index c01a84517..d0f50d156 100644 --- a/foreign_cc/configure.bzl +++ b/foreign_cc/configure.bzl @@ -212,14 +212,6 @@ def _attrs(): mandatory = False, default = "--prefix=", ), - "set_file_prefix_map": attr.bool( - doc = ( - "Use -ffile-prefix-map with the intention to remove the sandbox path from " + - "debug symbols" - ), - mandatory = False, - default = False, - ), "targets": attr.string_list( doc = ( "A list of targets within the foreign build system to produce. An empty string (`\"\"`) will result in " + diff --git a/foreign_cc/make.bzl b/foreign_cc/make.bzl index 6578a6f84..fcdd8a5cf 100644 --- a/foreign_cc/make.bzl +++ b/foreign_cc/make.bzl @@ -91,14 +91,6 @@ def _attrs(): mandatory = False, default = "$$INSTALLDIR$$", ), - "set_file_prefix_map": attr.bool( - doc = ( - "Use -ffile-prefix-map with the intention to remove the sandbox path from " + - "debug symbols" - ), - mandatory = False, - default = False, - ), "targets": attr.string_list( doc = ( "A list of targets within the foreign build system to produce. An empty string (`\"\"`) will result in " + diff --git a/foreign_cc/meson.bzl b/foreign_cc/meson.bzl index 8b057d02b..9d4179ab2 100644 --- a/foreign_cc/meson.bzl +++ b/foreign_cc/meson.bzl @@ -174,14 +174,6 @@ def _attrs(): mandatory = False, default = {}, ), - "set_file_prefix_map": attr.bool( - doc = ( - "Use -ffile-prefix-map with the intention to remove the sandbox path from " + - "debug symbols" - ), - mandatory = False, - default = False, - ), "setup_args": attr.string_list( doc = "Arguments for the Meson setup command", mandatory = False, diff --git a/foreign_cc/ninja.bzl b/foreign_cc/ninja.bzl index f3266affc..9b872e622 100644 --- a/foreign_cc/ninja.bzl +++ b/foreign_cc/ninja.bzl @@ -101,14 +101,6 @@ def _attrs(): "directory of the `lib_sources` attribute if this attribute is not set" ), ), - "set_file_prefix_map": attr.bool( - doc = ( - "Use -ffile-prefix-map with the intention to remove the sandbox path from " + - "debug symbols" - ), - mandatory = False, - default = False, - ), }) return attrs diff --git a/foreign_cc/private/framework.bzl b/foreign_cc/private/framework.bzl index 892467e58..1bb947b6e 100644 --- a/foreign_cc/private/framework.bzl +++ b/foreign_cc/private/framework.bzl @@ -201,6 +201,14 @@ CC_EXTERNAL_RULE_ATTRIBUTES = { doc = "Optional part of the shell script to be added after the make commands", mandatory = False, ), + "set_file_prefix_map": attr.bool( + doc = ( + "Use -ffile-prefix-map with the intention to remove the sandbox path from " + + "debug symbols" + ), + mandatory = False, + default = False, + ), "targets": attr.string_list( doc = ( "A list of targets with in the foreign build system to produce. An empty string (`\"\"`) will result in " +