Skip to content

Commit 6bcbd07

Browse files
authored
Merge pull request #73642 from edymtt/edymtt/swift-args-for-debug-info-non-lto-6.0
🍒 6.0: allow custom options when building the compiler with debug info
2 parents 83a35a0 + 2cb7edc commit 6bcbd07

File tree

6 files changed

+76
-1
lines changed

6 files changed

+76
-1
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,9 @@ option(SWIFT_STDLIB_ENABLE_OBJC_INTEROP
631631
"Should stdlib be built with Obj-C interop."
632632
"${SWIFT_STDLIB_ENABLE_OBJC_INTEROP_default}")
633633

634+
set(SWIFT_DEBUGINFO_NON_LTO_ARGS "-g" CACHE STRING
635+
"Compiler options to use when building the compiler in debug or debuginfo mode. These do not apply when linking with LTO")
636+
634637
#
635638
# User-configurable experimental options. Do not use in production builds.
636639
#

cmake/modules/AddSwift.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ function(_add_host_variant_c_compile_flags target)
227227
if(_lto_flag_out)
228228
target_compile_options(${target} PRIVATE $<$<COMPILE_LANGUAGE:C,CXX,OBJC,OBJCXX>:-gline-tables-only>)
229229
else()
230-
target_compile_options(${target} PRIVATE -g)
230+
target_compile_options(${target} PRIVATE ${SWIFT_DEBUGINFO_NON_LTO_ARGS})
231231
endif()
232232
else()
233233
target_compile_options(${target} PRIVATE $<$<COMPILE_LANGUAGE:C,CXX,OBJC,OBJCXX>:-g0>)

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,14 @@ def create_argument_parser():
439439
'list "module_regexp;flag". Can be called multiple times to '
440440
'add multiple such module_regexp flag pairs. All semicolons '
441441
'in flags must be escaped with a "\\"')
442+
option('--swift-debuginfo-non-lto-args', append,
443+
# We cannot set the default value directly here,
444+
# since it will be prepended to any option the user provides.
445+
default=None,
446+
help='Compilation flags to use when building the swift compiler '
447+
' in debug or debug info mode. Does not apply when building with '
448+
' LTO. Defaults to the default value of the CMake cache variable '
449+
' SWIFT_DEBUGINFO_NON_LTO_ARGS for Swift.')
442450

443451
option('--host-cc', store_path(executable=True),
444452
help='the absolute path to CC, the "clang" compiler for the host '

utils/build_swift/tests/expected_options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@
191191
'export_compile_commands': False,
192192
'extra_cmake_options': [],
193193
'extra_swift_args': [],
194+
'swift_debuginfo_non_lto_args': None,
194195
'force_optimized_typechecker': False,
195196
'foundation_build_variant': 'Debug',
196197
'host_cc': None,
@@ -827,6 +828,7 @@ class BuildScriptImplOption(_BaseOption):
827828
SetTrueOption('--infer-cross-compile-hosts-on-darwin'),
828829
AppendOption('--extra-cmake-options'),
829830
AppendOption('--extra-swift-args'),
831+
AppendOption('--swift-debuginfo-non-lto-args'),
830832
AppendOption('--test-paths'),
831833
AppendOption('--llvm-ninja-targets'),
832834
AppendOption('--llvm-ninja-targets-for-cross-compile-hosts'),

utils/swift_build_support/swift_build_support/products/swift.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ def __init__(self, args, toolchain, source_dir, build_dir):
8787
self.cmake_options.extend(
8888
self._enable_experimental_parser_validation)
8989

90+
self._handle_swift_debuginfo_non_lto_args()
91+
9092
@classmethod
9193
def is_build_script_impl_product(cls):
9294
"""is_build_script_impl_product -> bool
@@ -246,6 +248,18 @@ def _enable_experimental_parser_validation(self):
246248
return [('SWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION:BOOL',
247249
self.args.enable_experimental_parser_validation)]
248250

251+
def _handle_swift_debuginfo_non_lto_args(self):
252+
if ('swift_debuginfo_non_lto_args' not in self.args
253+
or self.args.swift_debuginfo_non_lto_args is None):
254+
# Ensure the final value of the variable is determined
255+
# by the build-script invocation, and not by any value present
256+
# in CMakeCache.txt (e.g. as a result of previous incremental builds)
257+
self.cmake_options.undefine('SWIFT_DEBUGINFO_NON_LTO_ARGS')
258+
else:
259+
self.cmake_options.extend(
260+
[('SWIFT_DEBUGINFO_NON_LTO_ARGS:STRING',
261+
";".join(self.args.swift_debuginfo_non_lto_args))])
262+
249263
@classmethod
250264
def get_dependencies(cls):
251265
return [cmark.CMark,

utils/swift_build_support/tests/products/test_swift.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ def test_by_default_no_cmake_options(self):
114114
'-DSWIFT_STDLIB_BUILD_PRIVATE:BOOL=TRUE',
115115
'-DSWIFT_STDLIB_ENABLE_UNICODE_DATA=TRUE',
116116
'-DSWIFT_TOOLS_LD64_LTO_CODEGEN_ONLY_FOR_SUPPORTING_TARGETS:BOOL=FALSE',
117+
'-USWIFT_DEBUGINFO_NON_LTO_ARGS'
117118
]
118119
self.assertEqual(set(swift.cmake_options), set(expected))
119120

@@ -144,6 +145,7 @@ def test_swift_runtime_tsan(self):
144145
'-DSWIFT_STDLIB_BUILD_PRIVATE:BOOL=TRUE',
145146
'-DSWIFT_STDLIB_ENABLE_UNICODE_DATA=TRUE',
146147
'-DSWIFT_TOOLS_LD64_LTO_CODEGEN_ONLY_FOR_SUPPORTING_TARGETS:BOOL=FALSE',
148+
'-USWIFT_DEBUGINFO_NON_LTO_ARGS'
147149
]
148150
self.assertEqual(set(swift.cmake_options), set(flags_set))
149151

@@ -497,3 +499,49 @@ def test_swift_tools_ld64_lto_codegen_only_for_supporting_targets(self):
497499
'TRUE'],
498500
[x for x in swift.cmake_options
499501
if 'SWIFT_TOOLS_LD64_LTO_CODEGEN_ONLY_FOR_SUPPORTING_TARGETS' in x])
502+
503+
def test_swift_debuginfo_non_lto_args(self):
504+
self.args.swift_debuginfo_non_lto_args = None
505+
swift = Swift(
506+
args=self.args,
507+
toolchain=self.toolchain,
508+
source_dir='/path/to/src',
509+
build_dir='/path/to/build')
510+
self.assertIn(
511+
'-USWIFT_DEBUGINFO_NON_LTO_ARGS',
512+
swift.cmake_options)
513+
514+
self.args.swift_debuginfo_non_lto_args = []
515+
swift = Swift(
516+
args=self.args,
517+
toolchain=self.toolchain,
518+
source_dir='/path/to/src',
519+
build_dir='/path/to/build')
520+
self.assertEqual(
521+
['-DSWIFT_DEBUGINFO_NON_LTO_ARGS:STRING='],
522+
[x for x in swift.cmake_options
523+
if 'SWIFT_DEBUGINFO_NON_LTO_ARGS' in x])
524+
525+
self.args.swift_debuginfo_non_lto_args = ['-g']
526+
swift = Swift(
527+
args=self.args,
528+
toolchain=self.toolchain,
529+
source_dir='/path/to/src',
530+
build_dir='/path/to/build')
531+
self.assertEqual(
532+
['-DSWIFT_DEBUGINFO_NON_LTO_ARGS:STRING='
533+
'-g'],
534+
[x for x in swift.cmake_options
535+
if 'SWIFT_DEBUGINFO_NON_LTO_ARGS' in x])
536+
537+
self.args.swift_debuginfo_non_lto_args = ['-gline-tables-only', '-v']
538+
swift = Swift(
539+
args=self.args,
540+
toolchain=self.toolchain,
541+
source_dir='/path/to/src',
542+
build_dir='/path/to/build')
543+
self.assertEqual(
544+
['-DSWIFT_DEBUGINFO_NON_LTO_ARGS:STRING='
545+
'-gline-tables-only;-v'],
546+
[x for x in swift.cmake_options
547+
if 'SWIFT_DEBUGINFO_NON_LTO_ARGS' in x])

0 commit comments

Comments
 (0)