Skip to content

Commit 9157816

Browse files
committed
Add libxml2 build product
This patch adds the libxml2 build product as a dependency of building foundation.
1 parent 1977a68 commit 9157816

File tree

7 files changed

+159
-2
lines changed

7 files changed

+159
-2
lines changed

Diff for: utils/build-script-impl

+28
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ components=(
265265
libcxx
266266
libdispatch
267267
libicu
268+
libxml2
268269
llbuild
269270
lldb
270271
llvm
@@ -1263,6 +1264,7 @@ LIBDISPATCH_STATIC_SOURCE_DIR="${WORKSPACE}/swift-corelibs-libdispatch"
12631264
LIBICU_SOURCE_DIR="${WORKSPACE}/icu"
12641265
LIBCXX_SOURCE_DIR="${WORKSPACE}/llvm-project/libcxx"
12651266
EXPERIMENTAL_STRING_PROCESSING_SOURCE_DIR="${WORKSPACE}/swift-experimental-string-processing"
1267+
LIBXML2_SOURCE_DIR="${WORKSPACE}/libxml2"
12661268

12671269
# We cannot currently apply the normal rules of skipping here for LLVM. Even if
12681270
# we are skipping building LLVM, we still need to at least build a few tools
@@ -2516,6 +2518,30 @@ for host in "${ALL_HOSTS[@]}"; do
25162518
LIBICU_BUILD_ARGS=()
25172519
fi
25182520

2521+
if [[ ! "${SKIP_BUILD_LIBXML2}" ]]; then
2522+
BASE_INSTALL_DIR="$(get_host_install_destdir ${host})"
2523+
LIBXML2_HEADERS="${BASE_INSTALL_DIR}/usr/include/libxml2"
2524+
LIBXML2_LIBRARY="${BASE_INSTALL_DIR}/usr/lib/libxml2.a"
2525+
2526+
if [[ -z "${DRY_RUN}" && ! -d "${LIBXML2_HEADERS}" ]]; then
2527+
echo "Error: '${LIBXML2_HEADERS}' does not exist" 1>&2
2528+
exit 1
2529+
fi
2530+
2531+
if [[ -z "${DRY_RUN}" && ! -e "${LIBXML2_LIBRARY}" ]]; then
2532+
echo "Error: '${LIBXML2_LIBRARY}' does not exist" 1>&2
2533+
exit 1
2534+
fi
2535+
2536+
LIBXML2_BUILD_ARGS=(
2537+
-DLIBXML2_INCLUDE_DIR:PATH="${LIBXML2_HEADERS}"
2538+
-DLIBXML2_LIBRARY:PATH="${LIBXML2_LIBRARY}"
2539+
-DLIBXML2_DEFINITIONS="-DLIBXML_STATIC"
2540+
)
2541+
else
2542+
LIBXML2_BUILD_ARGS=()
2543+
fi
2544+
25192545
if [[ "${SKIP_CLEAN_FOUNDATION}" == "0" ]]
25202546
then
25212547
# The Swift project might have been changed, but CMake might
@@ -2542,6 +2568,8 @@ for host in "${ALL_HOSTS[@]}"; do
25422568

25432569
${LIBICU_BUILD_ARGS[@]}
25442570

2571+
${LIBXML2_BUILD_ARGS[@]}
2572+
25452573
-DFOUNDATION_PATH_TO_LIBDISPATCH_SOURCE=${LIBDISPATCH_SOURCE_DIR}
25462574
-DFOUNDATION_PATH_TO_LIBDISPATCH_BUILD=$(build_directory ${host} libdispatch)
25472575
-Ddispatch_DIR=$(build_directory ${host} libdispatch)/cmake/modules

Diff for: utils/build_swift/build_swift/driver_arguments.py

+14
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ 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+
9396
# Assertions are enabled by default.
9497
if args.assertions is None:
9598
args.assertions = True
@@ -709,6 +712,9 @@ def create_argument_parser():
709712
option('--libicu', toggle_true('build_libicu'),
710713
help='build libicu')
711714

715+
option('--static-libxml2', toggle_true('build_libxml2'), default=False,
716+
help='build static libxml2')
717+
712718
option('--playgroundsupport', toggle_true('build_playgroundsupport'),
713719
help='build PlaygroundSupport')
714720
option('--install-playgroundsupport',
@@ -820,6 +826,11 @@ def create_argument_parser():
820826
const='Debug',
821827
help='build the Debug variant of libicu')
822828

829+
option('--debug-libxml2', store('libxml2_build_variant'),
830+
const='Debug',
831+
help='build the Debug variant of libxml2')
832+
833+
823834
# -------------------------------------------------------------------------
824835
# Assertions group
825836

@@ -1252,6 +1263,8 @@ def create_argument_parser():
12521263
help='skip building llvm')
12531264
option('--skip-build-swift', toggle_false('build_swift'),
12541265
help='skip building swift')
1266+
option('--skip-build-libxml2', toggle_false('build_libxml2'),
1267+
help='skip building libxml2')
12551268

12561269
# We need to list --skip-test-swift explicitly because otherwise argparse
12571270
# will auto-expand arguments like --skip-test-swift to the only known
@@ -1330,6 +1343,7 @@ def create_argument_parser():
13301343
/swift-corelibs-foundation (optional)
13311344
/swift-corelibs-libdispatch (optional)
13321345
/icu (optional)
1346+
/libxml2 (optional)
13331347
13341348
SWIFT_BUILD_ROOT: a directory in which to create out-of-tree builds.
13351349
Defaults to "$SWIFT_SOURCE_ROOT/build/".

Diff for: utils/build_swift/tests/expected_options.py

+5
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
'build_jobs': multiprocessing.cpu_count(),
6767
'build_libdispatch': False,
6868
'build_libicu': False,
69+
'build_libxml2': False,
6970
'build_linux': True,
7071
'build_llbuild': False,
7172
'build_lldb': False,
@@ -181,6 +182,7 @@
181182
'legacy_impl': False,
182183
'libdispatch_build_variant': 'Debug',
183184
'libicu_build_variant': 'Debug',
185+
'libxml2_build_variant': 'Debug',
184186
'bootstrapping_mode': None,
185187
'lit_args': '-sv',
186188
'llbuild_assertions': True,
@@ -429,6 +431,7 @@ class BuildScriptImplOption(_BaseOption):
429431
SetOption('--debug-libdispatch',
430432
dest='libdispatch_build_variant', value='Debug'),
431433
SetOption('--debug-libicu', dest='libicu_build_variant', value='Debug'),
434+
SetOption('--debug-libxml2', dest='libxml2_build_variant', value='Debug'),
432435
SetOption('--debug-lldb', dest='lldb_build_variant', value='Debug'),
433436
SetOption('--lldb-build-with-xcode', dest='lldb_build_with_xcode',
434437
value='1'),
@@ -560,6 +563,7 @@ class BuildScriptImplOption(_BaseOption):
560563
EnableOption('--only-non-executable-test'),
561564
EnableOption('--libdispatch', dest='build_libdispatch'),
562565
EnableOption('--libicu', dest='build_libicu'),
566+
EnableOption('--static-libxml2', dest='build_libxml2'),
563567
EnableOption('--indexstore-db', dest='build_indexstoredb'),
564568
EnableOption('--test-indexstore-db-sanitize-all',
565569
dest='test_indexstoredb_sanitize_all'),
@@ -663,6 +667,7 @@ class BuildScriptImplOption(_BaseOption):
663667
dest='test_swift_inspect'),
664668
DisableOption('--skip-build-clang-tools-extra',
665669
dest='build_clang_tools_extra'),
670+
DisableOption('--skip-build-libxml2', dest='build_libxml2'),
666671

667672
ChoicesOption('--compiler-vendor',
668673
choices=['none', 'apple']),

Diff for: utils/swift_build_support/swift_build_support/build_script_invocation.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ 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')
258259
]
259260
for (should_build, string_name) in conditional_subproject_configs:
260261
if not should_build and not self.args.infer_dependencies:
@@ -541,6 +542,9 @@ def compute_product_pipelines(self):
541542
builder.add_product(products.CMark,
542543
is_enabled=self.args.build_cmark)
543544

545+
builder.add_product(products.LibXML2,
546+
is_enabled=self.args.build_libxml2)
547+
544548
# Begin a build-script-impl pipeline for handling the compiler toolchain
545549
# and a subset of the tools that we build. We build these in this manner
546550
# to preserve current build-script-impl run behavior as we transition

Diff for: utils/swift_build_support/swift_build_support/products/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from .libcxx import LibCXX
2020
from .libdispatch import LibDispatch
2121
from .libicu import LibICU
22+
from .libxml2 import LibXML2
2223
from .llbuild import LLBuild
2324
from .lldb import LLDB
2425
from .llvm import LLVM
@@ -46,6 +47,7 @@
4647
'LibCXX',
4748
'LibDispatch',
4849
'LibICU',
50+
'LibXML2',
4951
'LLBuild',
5052
'LLDB',
5153
'LLVM',

Diff for: utils/swift_build_support/swift_build_support/products/foundation.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from . import libcxx
1515
from . import libdispatch
1616
from . import libicu
17+
from . import libxml2
1718
from . import llvm
1819
from . import product
1920
from . import swift
@@ -51,7 +52,8 @@ def get_dependencies(cls):
5152
libcxx.LibCXX,
5253
libicu.LibICU,
5354
swift.Swift,
54-
libdispatch.LibDispatch]
55+
libdispatch.LibDispatch,
56+
libxml2.LibXML2]
5557

5658
@classmethod
5759
def is_nondarwin_only_build_product(cls):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# swift_build_support/products/libxml2.py ------------------------------------
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See https://swift.org/LICENSE.txt for license information
9+
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
#
11+
# ----------------------------------------------------------------------------
12+
13+
from . import cmake_product
14+
from . import earlyswiftdriver
15+
16+
17+
class LibXML2(cmake_product.CMakeProduct):
18+
@classmethod
19+
def is_build_script_impl_product(cls):
20+
"""is_build_script_impl_product -> bool
21+
22+
Whether this product is produced by build-script-impl
23+
"""
24+
return False
25+
26+
@classmethod
27+
def is_before_build_script_impl_product(cls):
28+
"""is_before_build_script_impl_product -> bool
29+
30+
Whether this product is built before any build-script-impl products
31+
"""
32+
return True
33+
34+
@classmethod
35+
def is_nondarwin_only_build_product(cls):
36+
return True
37+
38+
@classmethod
39+
def get_dependencies(cls):
40+
return [earlyswiftdriver.EarlySwiftDriver]
41+
42+
def should_build(self, host_target):
43+
"""should_build() -> Bool
44+
45+
Return True if libxml2 should be built
46+
"""
47+
return self.args.build_libxml2
48+
49+
def should_test(self, host_target):
50+
"""should_test() -> Bool
51+
52+
Returns True if libxml2 should be tested.
53+
Currently is set to false
54+
"""
55+
return False
56+
57+
def should_install(self, host_target):
58+
"""should_install() -> Bool
59+
60+
Returns True if we're building libxml2
61+
"""
62+
return self.args.build_libxml2
63+
64+
def install(self, host_target):
65+
"""
66+
Install libxml2 to the target location
67+
"""
68+
path = self.host_install_destdir(host_target)
69+
self.install_with_cmake(['install'], path)
70+
71+
def build(self, host_target):
72+
self.cmake_options.define('BUILD_SHARED_LIBS', 'NO')
73+
self.cmake_options.define('CMAKE_POSITION_INDEPENDENT_CODE', 'YES')
74+
75+
if self.args.libxml2_build_variant is None:
76+
self.args.libxml2_build_variant = "Release"
77+
self.cmake_options.define('CMAKE_BUILD_TYPE:STRING',
78+
self.args.libxml2_build_variant)
79+
self.cmake_options.define('CMAKE_INSTALL_PREFIX', '/usr')
80+
self.cmake_options.define('LIBXML2_WITH_THREADS', 'YES')
81+
self.cmake_options.define('LIBXML2_WITH_ICONV', 'NO')
82+
self.cmake_options.define('LIBXML2_WITH_ICU', 'NO')
83+
self.cmake_options.define('LIBXML2_WITH_LZMA', 'NO')
84+
self.cmake_options.define('LIBXML2_WITH_PYTHON', 'NO')
85+
self.cmake_options.define('LIBXML2_WITH_TESTS', 'NO')
86+
self.cmake_options.define('LIBXML2_WITH_ZLIB', 'NO')
87+
88+
(platform, arch) = host_target.split('-')
89+
common_c_flags = ' '.join(self.common_cross_c_flags(platform, arch))
90+
self.cmake_options.define('CMAKE_C_FLAGS', common_c_flags)
91+
self.cmake_options.define('CMAKE_CXX_FLAGS', common_c_flags)
92+
93+
if host_target.startswith("macosx") or \
94+
host_target.startswith("iphone") or \
95+
host_target.startswith("appletv") or \
96+
host_target.startswith("watch"):
97+
toolchain_file = self.generate_darwin_toolchain_file(platform, arch)
98+
self.cmake_options.define('CMAKE_TOOLCHAIN_FILE:PATH', toolchain_file)
99+
elif platform == "linux":
100+
toolchain_file = self.generate_linux_toolchain_file(platform, arch)
101+
self.cmake_options.define('CMAKE_TOOLCHAIN_FILE:PATH', toolchain_file)
102+
self.build_with_cmake(["LibXml2"], self.args.libxml2_build_variant, [])

0 commit comments

Comments
 (0)