Skip to content

Commit 7dadb09

Browse files
authored
Merge pull request #42253 from etcwilde/ewilde/build-foundation-dependencies
Teach build-script to build Foundation Dependencies (Zlib, libxml2, LibCurl)
2 parents 2d43be6 + ef8c149 commit 7dadb09

File tree

9 files changed

+476
-2
lines changed

9 files changed

+476
-2
lines changed

utils/build-script-impl

+65
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@ components=(
265265
libcxx
266266
libdispatch
267267
libicu
268+
libxml2
269+
zlib
270+
curl
268271
llbuild
269272
lldb
270273
llvm
@@ -1262,6 +1265,7 @@ LIBDISPATCH_STATIC_SOURCE_DIR="${WORKSPACE}/swift-corelibs-libdispatch"
12621265
LIBICU_SOURCE_DIR="${WORKSPACE}/icu"
12631266
LIBCXX_SOURCE_DIR="${WORKSPACE}/llvm-project/libcxx"
12641267
EXPERIMENTAL_STRING_PROCESSING_SOURCE_DIR="${WORKSPACE}/swift-experimental-string-processing"
1268+
LIBXML2_SOURCE_DIR="${WORKSPACE}/libxml2"
12651269

12661270
# We cannot currently apply the normal rules of skipping here for LLVM. Even if
12671271
# we are skipping building LLVM, we still need to at least build a few tools
@@ -2524,6 +2528,61 @@ for host in "${ALL_HOSTS[@]}"; do
25242528
LIBICU_BUILD_ARGS=()
25252529
fi
25262530

2531+
if [[ ! "${SKIP_BUILD_LIBXML2}" ]]; then
2532+
BASE_INSTALL_DIR="$(get_host_install_destdir ${host})"
2533+
LIBXML2_HEADERS="${BASE_INSTALL_DIR}/usr/include/libxml2"
2534+
LIBXML2_LIBRARY="${BASE_INSTALL_DIR}/usr/lib/libxml2.a"
2535+
2536+
if [[ -z "${DRY_RUN}" && ! -d "${LIBXML2_HEADERS}" ]]; then
2537+
echo "Error: '${LIBXML2_HEADERS}' does not exist" 1>&2
2538+
exit 1
2539+
fi
2540+
2541+
if [[ -z "${DRY_RUN}" && ! -e "${LIBXML2_LIBRARY}" ]]; then
2542+
echo "Error: '${LIBXML2_LIBRARY}' does not exist" 1>&2
2543+
exit 1
2544+
fi
2545+
2546+
LIBXML2_BUILD_ARGS=(
2547+
-DLIBXML2_INCLUDE_DIR:PATH="${LIBXML2_HEADERS}"
2548+
-DLIBXML2_LIBRARY:PATH="${LIBXML2_LIBRARY}"
2549+
-DLIBXML2_DEFINITIONS="-DLIBXML_STATIC"
2550+
)
2551+
else
2552+
LIBXML2_BUILD_ARGS=()
2553+
fi
2554+
2555+
if [[ ! "${SKIP_BUILD_ZLIB}" ]]; then
2556+
BASE_INSTALL_DIR="$(get_host_install_destdir ${host})"
2557+
ZLIB_HEADERS="${BASE_INSTALL_DIR}/usr/include"
2558+
# Note: On Windows, the spelling is 'zlibstatic.lib',
2559+
# so if this is ported to python, that case will need
2560+
# to be handled.
2561+
ZLIB_LIBRARY="${BASE_INSTALL_DIR}/usr/lib/libz.a"
2562+
2563+
if [[ -z "${DRY_RUN}" && ! -d "${ZLIB_HEADERS}" ]]; then
2564+
echo "Error: '${ZLIB_HEADERS}' does not exist" 1>&2
2565+
exit 1
2566+
fi
2567+
2568+
if [[ -z "${DRY_RUN}" && ! -e "${ZLIB_LIBRARY}" ]]; then
2569+
echo "Error: '${ZLIB_LIBRARY}' does not exist" 1>&2
2570+
exit 1
2571+
fi
2572+
2573+
ZLIB_BUILD_ARGS=(
2574+
-DZLIB_INCLUDE_DIR:PATH="${ZLIB_HEADERS}"
2575+
-DZLIB_LIBRARY:PATH="${ZLIB_LIBRARY}"
2576+
)
2577+
fi
2578+
2579+
if [[ ! "${SKIP_BUILD_CURL}" ]]; then
2580+
BASE_INSTALL_DIR="$(get_host_install_destdir ${host})"
2581+
CURL_BUILD_ARGS=(
2582+
-DCURL_DIR="${BASE_INSTALL_DIR}/usr/lib/cmake/CURL"
2583+
)
2584+
fi
2585+
25272586
if [[ "${SKIP_CLEAN_FOUNDATION}" == "0" ]]
25282587
then
25292588
# The Swift project might have been changed, but CMake might
@@ -2550,6 +2609,12 @@ for host in "${ALL_HOSTS[@]}"; do
25502609

25512610
${LIBICU_BUILD_ARGS[@]}
25522611

2612+
${LIBXML2_BUILD_ARGS[@]}
2613+
2614+
${ZLIB_BUILD_ARGS[@]}
2615+
2616+
${CURL_BUILD_ARGS[@]}
2617+
25532618
-DFOUNDATION_PATH_TO_LIBDISPATCH_SOURCE=${LIBDISPATCH_SOURCE_DIR}
25542619
-DFOUNDATION_PATH_TO_LIBDISPATCH_BUILD=$(build_directory ${host} libdispatch)
25552620
-Ddispatch_DIR=$(build_directory ${host} libdispatch)/cmake/modules

utils/build_swift/build_swift/driver_arguments.py

+39
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ def _apply_default_arguments(args):
9090
if args.libicu_build_variant is None:
9191
args.libicu_build_variant = args.build_variant
9292

93+
if args.libxml2_build_variant is None:
94+
args.libxml2_build_variant = args.build_variant
95+
96+
if args.zlib_build_variant is None:
97+
args.zlib_build_variant = args.build_variant
98+
99+
if args.curl_build_variant is None:
100+
args.curl_build_variant = args.build_variant
101+
93102
# Assertions are enabled by default.
94103
if args.assertions is None:
95104
args.assertions = True
@@ -709,6 +718,15 @@ def create_argument_parser():
709718
option('--libicu', toggle_true('build_libicu'),
710719
help='build libicu')
711720

721+
option('--static-libxml2', toggle_true('build_libxml2'), default=False,
722+
help='build static libxml2')
723+
724+
option('--static-zlib', toggle_true('build_zlib'), default=False,
725+
help='build static zlib')
726+
727+
option('--static-curl', toggle_true('build_curl'), default=False,
728+
help='build static curl libraries')
729+
712730
option('--playgroundsupport', toggle_true('build_playgroundsupport'),
713731
help='build PlaygroundSupport')
714732
option('--install-playgroundsupport',
@@ -820,6 +838,18 @@ def create_argument_parser():
820838
const='Debug',
821839
help='build the Debug variant of libicu')
822840

841+
option('--debug-libxml2', store('libxml2_build_variant'),
842+
const='Debug',
843+
help='build the Debug variant of libxml2')
844+
845+
option('--debug-zlib', store('zlib_build_variant'),
846+
const='Debug',
847+
help='build the Debug variant of zlib')
848+
849+
option('--debug-curl', store('curl_build_variant'),
850+
const='Debug',
851+
help='build the Debug variant of libcurl')
852+
823853
# -------------------------------------------------------------------------
824854
# Assertions group
825855

@@ -1252,6 +1282,12 @@ def create_argument_parser():
12521282
help='skip building llvm')
12531283
option('--skip-build-swift', toggle_false('build_swift'),
12541284
help='skip building swift')
1285+
option('--skip-build-libxml2', toggle_false('build_libxml2'),
1286+
help='skip building libxml2')
1287+
option('--skip-build-zlib', toggle_false('build_zlib'),
1288+
help='skip building zlib')
1289+
option('--skip-build-curl', toggle_false('build_curl'),
1290+
help='skip building curl')
12551291

12561292
# We need to list --skip-test-swift explicitly because otherwise argparse
12571293
# will auto-expand arguments like --skip-test-swift to the only known
@@ -1330,6 +1366,9 @@ def create_argument_parser():
13301366
/swift-corelibs-foundation (optional)
13311367
/swift-corelibs-libdispatch (optional)
13321368
/icu (optional)
1369+
/libxml2 (optional)
1370+
/zlib (optional)
1371+
/curl (optional)
13331372
13341373
SWIFT_BUILD_ROOT: a directory in which to create out-of-tree builds.
13351374
Defaults to "$SWIFT_SOURCE_ROOT/build/".

utils/build_swift/tests/expected_options.py

+15
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@
6666
'build_jobs': multiprocessing.cpu_count(),
6767
'build_libdispatch': False,
6868
'build_libicu': False,
69+
'build_libxml2': False,
70+
'build_zlib': False,
71+
'build_curl': False,
6972
'build_linux': True,
7073
'build_llbuild': False,
7174
'build_lldb': False,
@@ -181,6 +184,9 @@
181184
'legacy_impl': False,
182185
'libdispatch_build_variant': 'Debug',
183186
'libicu_build_variant': 'Debug',
187+
'libxml2_build_variant': 'Debug',
188+
'zlib_build_variant': 'Debug',
189+
'curl_build_variant': 'Debug',
184190
'bootstrapping_mode': None,
185191
'lit_args': '-sv',
186192
'llbuild_assertions': True,
@@ -429,6 +435,9 @@ class BuildScriptImplOption(_BaseOption):
429435
SetOption('--debug-libdispatch',
430436
dest='libdispatch_build_variant', value='Debug'),
431437
SetOption('--debug-libicu', dest='libicu_build_variant', value='Debug'),
438+
SetOption('--debug-libxml2', dest='libxml2_build_variant', value='Debug'),
439+
SetOption('--debug-zlib', dest='zlib_build_variant', value='Debug'),
440+
SetOption('--debug-curl', dest='curl_build_variant', value='Debug'),
432441
SetOption('--debug-lldb', dest='lldb_build_variant', value='Debug'),
433442
SetOption('--lldb-build-with-xcode', dest='lldb_build_with_xcode',
434443
value='1'),
@@ -560,6 +569,9 @@ class BuildScriptImplOption(_BaseOption):
560569
EnableOption('--only-non-executable-test'),
561570
EnableOption('--libdispatch', dest='build_libdispatch'),
562571
EnableOption('--libicu', dest='build_libicu'),
572+
EnableOption('--static-libxml2', dest='build_libxml2'),
573+
EnableOption('--static-zlib', dest='build_zlib'),
574+
EnableOption('--static-curl', dest='build_curl'),
563575
EnableOption('--indexstore-db', dest='build_indexstoredb'),
564576
EnableOption('--test-indexstore-db-sanitize-all',
565577
dest='test_indexstoredb_sanitize_all'),
@@ -663,6 +675,9 @@ class BuildScriptImplOption(_BaseOption):
663675
dest='test_swift_inspect'),
664676
DisableOption('--skip-build-clang-tools-extra',
665677
dest='build_clang_tools_extra'),
678+
DisableOption('--skip-build-libxml2', dest='build_libxml2'),
679+
DisableOption('--skip-build-zlib', dest='build_zlib'),
680+
DisableOption('--skip-build-curl', dest='build_curl'),
666681

667682
ChoicesOption('--compiler-vendor',
668683
choices=['none', 'apple']),

utils/swift_build_support/swift_build_support/build_script_invocation.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,10 @@ def convert_to_impl_arguments(self):
254254
(args.build_llbuild, "llbuild"),
255255
(args.build_libcxx, "libcxx"),
256256
(args.build_libdispatch, "libdispatch"),
257-
(args.build_libicu, "libicu")
257+
(args.build_libicu, "libicu"),
258+
(args.build_libxml2, 'libxml2'),
259+
(args.build_zlib, 'zlib'),
260+
(args.build_curl, 'curl')
258261
]
259262
for (should_build, string_name) in conditional_subproject_configs:
260263
if not should_build and not self.args.infer_dependencies:
@@ -541,6 +544,15 @@ def compute_product_pipelines(self):
541544
builder.add_product(products.CMark,
542545
is_enabled=self.args.build_cmark)
543546

547+
builder.add_product(products.LibXML2,
548+
is_enabled=self.args.build_libxml2)
549+
550+
builder.add_product(products.zlib.Zlib,
551+
is_enabled=self.args.build_zlib)
552+
553+
builder.add_product(products.curl.LibCurl,
554+
is_enabled=self.args.build_curl)
555+
544556
# Begin a build-script-impl pipeline for handling the compiler toolchain
545557
# and a subset of the tools that we build. We build these in this manner
546558
# to preserve current build-script-impl run behavior as we transition

utils/swift_build_support/swift_build_support/products/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313
from .backdeployconcurrency import BackDeployConcurrency
1414
from .benchmarks import Benchmarks
1515
from .cmark import CMark
16+
from .curl import LibCurl
1617
from .earlyswiftdriver import EarlySwiftDriver
1718
from .foundation import Foundation
1819
from .indexstoredb import IndexStoreDB
1920
from .libcxx import LibCXX
2021
from .libdispatch import LibDispatch
2122
from .libicu import LibICU
23+
from .libxml2 import LibXML2
2224
from .llbuild import LLBuild
2325
from .lldb import LLDB
2426
from .llvm import LLVM
@@ -37,6 +39,7 @@
3739
from .swiftsyntax import SwiftSyntax
3840
from .tsan_libdispatch import TSanLibDispatch
3941
from .xctest import XCTest
42+
from .zlib import Zlib
4043

4144
__all__ = [
4245
'BackDeployConcurrency',
@@ -46,6 +49,9 @@
4649
'LibCXX',
4750
'LibDispatch',
4851
'LibICU',
52+
'LibXML2',
53+
'Zlib',
54+
'LibCurl',
4955
'LLBuild',
5056
'LLDB',
5157
'LLVM',

0 commit comments

Comments
 (0)