[CMake][Release] Statically link clang with stage1 runtimes (#127268) · llvm/llvm-project@dc1bd6a (original) (raw)

`@@ -48,10 +48,8 @@ set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")

`

48

48

``

49

49

`set(STAGE1_PROJECTS "clang")

`

50

50

``

51

``

`-

Building Flang on Windows requires compiler-rt, so we need to build it in

`

52

``

`-

stage1. compiler-rt is also required for building the Flang tests on

`

53

``

`-

macOS.

`

54

``

`-

set(STAGE1_RUNTIMES "compiler-rt")

`

``

51

`+

Build all runtimes so we can statically link them into the stage2 compiler.

`

``

52

`+

set(STAGE1_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind")

`

55

53

``

56

54

`if (LLVM_RELEASE_ENABLE_PGO)

`

57

55

`list(APPEND STAGE1_PROJECTS "lld")

`

`@@ -90,9 +88,20 @@ else()

`

90

88

`set(CLANG_BOOTSTRAP_TARGETS ${LLVM_RELEASE_FINAL_STAGE_TARGETS} CACHE STRING "")

`

91

89

`endif()

`

92

90

``

``

91

`+

if (LLVM_RELEASE_ENABLE_LTO)

`

``

92

`+

Enable LTO for the runtimes. We need to configure stage1 clang to default

`

``

93

`+

to using lld as the linker because the stage1 toolchain will be used to

`

``

94

`+

build and link the runtimes.

`

``

95

`+

FIXME: We can't use LLVM_ENABLE_LTO=Thin here, because it causes the CMake

`

``

96

`+

step for the libcxx build to fail. CMAKE_INTERPROCEDURAL_OPTIMIZATION does

`

``

97

`+

enable ThinLTO, though.

`

``

98

`+

set(RUNTIMES_CMAKE_ARGS "-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON -DLLVM_ENABLE_LLD=ON" CACHE STRING "")

`

``

99

`+

endif()

`

``

100

+

93

101

`# Stage 1 Common Config

`

94

102

`set(LLVM_ENABLE_RUNTIMES ${STAGE1_RUNTIMES} CACHE STRING "")

`

95

103

`set(LLVM_ENABLE_PROJECTS ${STAGE1_PROJECTS} CACHE STRING "")

`

``

104

`+

set(LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY ON CACHE STRING "")

`

96

105

``

97

106

`# stage2-instrumented and Final Stage Config:

`

98

107

`# Options that need to be set in both the instrumented stage (if we are doing

`

`@@ -102,6 +111,16 @@ set_instrument_and_final_stage_var(LLVM_ENABLE_LTO "${LLVM_RELEASE_ENABLE_LTO}"

`

102

111

`if (LLVM_RELEASE_ENABLE_LTO)

`

103

112

`set_instrument_and_final_stage_var(LLVM_ENABLE_LLD "ON" BOOL)

`

104

113

`endif()

`

``

114

`+

set_instrument_and_final_stage_var(LLVM_ENABLE_LIBCXX "ON" BOOL)

`

``

115

`+

set_instrument_and_final_stage_var(LLVM_STATIC_LINK_CXX_STDLIB "ON" BOOL)

`

``

116

`+

set(RELEASE_LINKER_FLAGS "-rtlib=compiler-rt --unwindlib=libunwind")

`

``

117

`+

if(NOT ${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")

`

``

118

`+

set(RELEASE_LINKER_FLAGS "${RELEASE_LINKER_FLAGS} -static-libgcc")

`

``

119

`+

endif()

`

``

120

+

``

121

`+

set_instrument_and_final_stage_var(CMAKE_EXE_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING)

`

``

122

`+

set_instrument_and_final_stage_var(CMAKE_SHARED_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING)

`

``

123

`+

set_instrument_and_final_stage_var(CMAKE_MODULE_LINKER_FLAGS ${RELEASE_LINKER_FLAGS} STRING)

`

105

124

``

106

125

`# Final Stage Config (stage2)

`

107

126

`set_final_stage_var(LLVM_ENABLE_RUNTIMES "${LLVM_RELEASE_ENABLE_RUNTIMES}" STRING)

`