Skip to content

Commit 1fbdaee

Browse files
committed
[Platform] Unify Linux/FreeBSD modulemaps with gyb
A great deal of duplication exists across the Linux and FreeBSD modulemaps. An Android modulemap would add even more duplication. Use gyb to conditionally include certain exports for certain platforms. Most of glibc.modulemap is common across Linux and FreeBSD, and using gyb we can conditionally include the two exports that differ.
1 parent 28401eb commit 1fbdaee

File tree

3 files changed

+26
-379
lines changed

3 files changed

+26
-379
lines changed

stdlib/public/Platform/CMakeLists.txt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ foreach(sdk ${SWIFT_SDKS})
3535
set(arch_subdir "${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}")
3636
set(module_dir "${SWIFTLIB_DIR}/${arch_subdir}")
3737

38-
set(glibc_modulemap_source "glibc.${SWIFT_SDK_${sdk}_TRIPLE_NAME}.modulemap.in")
39-
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${glibc_modulemap_source}")
40-
set(glibc_modulemap_source "glibc.modulemap.in")
41-
endif()
42-
4338
# Determine the location of glibc headers based on the target.
4439
set(GLIBC_INCLUDE_PATH "/usr/include")
4540
set(GLIBC_ARCH_INCLUDE_PATH ${GLIBC_INCLUDE_PATH})
@@ -55,11 +50,24 @@ foreach(sdk ${SWIFT_SDKS})
5550

5651
# Configure the module map based on the target. Each platform needs to
5752
# reference different headers, based on what's available in their glibc.
53+
set(glibc_modulemap_gyb_source "glibc.modulemap.in.gyb")
54+
set(glibc_modulemap_gyb_configured
55+
"${CMAKE_CURRENT_BINARY_DIR}/${arch_subdir}/glibc.modulemap.gyb")
56+
configure_file(
57+
${glibc_modulemap_gyb_source}
58+
${glibc_modulemap_gyb_configured}
59+
@ONLY)
60+
61+
set(gyb_tool "${SWIFT_SOURCE_DIR}/utils/gyb")
5862
set(glibc_modulemap_configured
5963
"${CMAKE_CURRENT_BINARY_DIR}/${arch_subdir}/glibc.modulemap")
60-
configure_file(${glibc_modulemap_source} ${glibc_modulemap_configured} @ONLY)
61-
6264
add_custom_command_target(glibc_modulemap_target
65+
# We can't use handle_gyb_sources() here because we need to ensure
66+
# gyb is invoked before we copy glibc.modulemap into the module dir.
67+
# FIXME: Instead of using a combination of configure_file() and gyb,
68+
# we should use just gyb--it'd be simpler.
69+
COMMAND
70+
${gyb_tool} "-DCMAKE_SDK=${sdk}" -o ${glibc_modulemap_configured} ${glibc_modulemap_gyb_configured}
6371
COMMAND
6472
${CMAKE_COMMAND} -E make_directory ${module_dir}
6573
COMMAND

0 commit comments

Comments
 (0)