Skip to content

Commit d718474

Browse files
committed
Add zlib build product
This patch adds a zlib and static-zlib build product, respectively producing a dynamic and static zlib library. This is a dependency of building Foundation.
1 parent 9157816 commit d718474

File tree

7 files changed

+152
-2
lines changed

7 files changed

+152
-2
lines changed

utils/build-script-impl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ components=(
266266
libdispatch
267267
libicu
268268
libxml2
269+
zlib
269270
llbuild
270271
lldb
271272
llvm
@@ -2542,6 +2543,30 @@ for host in "${ALL_HOSTS[@]}"; do
25422543
LIBXML2_BUILD_ARGS=()
25432544
fi
25442545

2546+
if [[ ! "${SKIP_BUILD_ZLIB}" ]]; then
2547+
BASE_INSTALL_DIR="$(get_host_install_destdir ${host})"
2548+
ZLIB_HEADERS="${BASE_INSTALL_DIR}/usr/include"
2549+
# Note: On Windows, the spelling is 'zlibstatic.lib',
2550+
# so if this is ported to python, that case will need
2551+
# to be handled.
2552+
ZLIB_LIBRARY="${BASE_INSTALL_DIR}/usr/lib/libz.a"
2553+
2554+
if [[ -z "${DRY_RUN}" && ! -d "${ZLIB_HEADERS}" ]]; then
2555+
echo "Error: '${ZLIB_HEADERS}' does not exist" 1>&2
2556+
exit 1
2557+
fi
2558+
2559+
if [[ -z "${DRY_RUN}" && ! -e "${ZLIB_LIBRARY}" ]]; then
2560+
echo "Error: '${ZLIB_LIBRARY}' does not exist" 1>&2
2561+
exit 1
2562+
fi
2563+
2564+
ZLIB_BUILD_ARGS=(
2565+
-DZLIB_INCLUDE_DIR:PATH="${ZLIB_HEADERS}"
2566+
-DZLIB_LIBRARY:PATH="${ZLIB_LIBRARY}"
2567+
)
2568+
fi
2569+
25452570
if [[ "${SKIP_CLEAN_FOUNDATION}" == "0" ]]
25462571
then
25472572
# The Swift project might have been changed, but CMake might
@@ -2570,6 +2595,8 @@ for host in "${ALL_HOSTS[@]}"; do
25702595

25712596
${LIBXML2_BUILD_ARGS[@]}
25722597

2598+
${ZLIB_BUILD_ARGS[@]}
2599+
25732600
-DFOUNDATION_PATH_TO_LIBDISPATCH_SOURCE=${LIBDISPATCH_SOURCE_DIR}
25742601
-DFOUNDATION_PATH_TO_LIBDISPATCH_BUILD=$(build_directory ${host} libdispatch)
25752602
-Ddispatch_DIR=$(build_directory ${host} libdispatch)/cmake/modules

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ def _apply_default_arguments(args):
9393
if args.libxml2_build_variant is None:
9494
args.libxml2_build_variant = args.build_variant
9595

96+
if args.zlib_build_variant is None:
97+
args.zlib_build_variant = args.build_variant
98+
9699
# Assertions are enabled by default.
97100
if args.assertions is None:
98101
args.assertions = True
@@ -715,6 +718,9 @@ def create_argument_parser():
715718
option('--static-libxml2', toggle_true('build_libxml2'), default=False,
716719
help='build static libxml2')
717720

721+
option('--static-zlib', toggle_true('build_zlib'), default=False,
722+
help='build static zlib')
723+
718724
option('--playgroundsupport', toggle_true('build_playgroundsupport'),
719725
help='build PlaygroundSupport')
720726
option('--install-playgroundsupport',
@@ -830,6 +836,9 @@ def create_argument_parser():
830836
const='Debug',
831837
help='build the Debug variant of libxml2')
832838

839+
option('--debug-zlib', store('zlib_build_variant'),
840+
const='Debug',
841+
help='build the Debug variant of zlib')
833842

834843
# -------------------------------------------------------------------------
835844
# Assertions group
@@ -1265,6 +1274,8 @@ def create_argument_parser():
12651274
help='skip building swift')
12661275
option('--skip-build-libxml2', toggle_false('build_libxml2'),
12671276
help='skip building libxml2')
1277+
option('--skip-build-zlib', toggle_false('build_zlib'),
1278+
help='skip building zlib')
12681279

12691280
# We need to list --skip-test-swift explicitly because otherwise argparse
12701281
# will auto-expand arguments like --skip-test-swift to the only known
@@ -1344,6 +1355,7 @@ def create_argument_parser():
13441355
/swift-corelibs-libdispatch (optional)
13451356
/icu (optional)
13461357
/libxml2 (optional)
1358+
/zlib (optional)
13471359
13481360
SWIFT_BUILD_ROOT: a directory in which to create out-of-tree builds.
13491361
Defaults to "$SWIFT_SOURCE_ROOT/build/".

utils/build_swift/tests/expected_options.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
'build_libdispatch': False,
6868
'build_libicu': False,
6969
'build_libxml2': False,
70+
'build_zlib': False,
7071
'build_linux': True,
7172
'build_llbuild': False,
7273
'build_lldb': False,
@@ -183,6 +184,7 @@
183184
'libdispatch_build_variant': 'Debug',
184185
'libicu_build_variant': 'Debug',
185186
'libxml2_build_variant': 'Debug',
187+
'zlib_build_variant': 'Debug',
186188
'bootstrapping_mode': None,
187189
'lit_args': '-sv',
188190
'llbuild_assertions': True,
@@ -432,6 +434,7 @@ class BuildScriptImplOption(_BaseOption):
432434
dest='libdispatch_build_variant', value='Debug'),
433435
SetOption('--debug-libicu', dest='libicu_build_variant', value='Debug'),
434436
SetOption('--debug-libxml2', dest='libxml2_build_variant', value='Debug'),
437+
SetOption('--debug-zlib', dest='zlib_build_variant', value='Debug'),
435438
SetOption('--debug-lldb', dest='lldb_build_variant', value='Debug'),
436439
SetOption('--lldb-build-with-xcode', dest='lldb_build_with_xcode',
437440
value='1'),
@@ -564,6 +567,7 @@ class BuildScriptImplOption(_BaseOption):
564567
EnableOption('--libdispatch', dest='build_libdispatch'),
565568
EnableOption('--libicu', dest='build_libicu'),
566569
EnableOption('--static-libxml2', dest='build_libxml2'),
570+
EnableOption('--static-zlib', dest='build_zlib'),
567571
EnableOption('--indexstore-db', dest='build_indexstoredb'),
568572
EnableOption('--test-indexstore-db-sanitize-all',
569573
dest='test_indexstoredb_sanitize_all'),
@@ -668,6 +672,7 @@ class BuildScriptImplOption(_BaseOption):
668672
DisableOption('--skip-build-clang-tools-extra',
669673
dest='build_clang_tools_extra'),
670674
DisableOption('--skip-build-libxml2', dest='build_libxml2'),
675+
DisableOption('--skip-build-zlib', dest='build_zlib'),
671676

672677
ChoicesOption('--compiler-vendor',
673678
choices=['none', 'apple']),

utils/swift_build_support/swift_build_support/build_script_invocation.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ def convert_to_impl_arguments(self):
255255
(args.build_libcxx, "libcxx"),
256256
(args.build_libdispatch, "libdispatch"),
257257
(args.build_libicu, "libicu"),
258-
(args.build_libxml2, 'libxml2')
258+
(args.build_libxml2, 'libxml2'),
259+
(args.build_zlib, 'zlib')
259260
]
260261
for (should_build, string_name) in conditional_subproject_configs:
261262
if not should_build and not self.args.infer_dependencies:
@@ -545,6 +546,9 @@ def compute_product_pipelines(self):
545546
builder.add_product(products.LibXML2,
546547
is_enabled=self.args.build_libxml2)
547548

549+
builder.add_product(products.zlib.Zlib,
550+
is_enabled=self.args.build_zlib)
551+
548552
# Begin a build-script-impl pipeline for handling the compiler toolchain
549553
# and a subset of the tools that we build. We build these in this manner
550554
# to preserve current build-script-impl run behavior as we transition

utils/swift_build_support/swift_build_support/products/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from .swiftsyntax import SwiftSyntax
3939
from .tsan_libdispatch import TSanLibDispatch
4040
from .xctest import XCTest
41+
from .zlib import Zlib
4142

4243
__all__ = [
4344
'BackDeployConcurrency',
@@ -48,6 +49,7 @@
4849
'LibDispatch',
4950
'LibICU',
5051
'LibXML2',
52+
'Zlib',
5153
'LLBuild',
5254
'LLDB',
5355
'LLVM',

utils/swift_build_support/swift_build_support/products/foundation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from . import llvm
1919
from . import product
2020
from . import swift
21+
from . import zlib
2122

2223

2324
class Foundation(product.Product):
@@ -53,7 +54,8 @@ def get_dependencies(cls):
5354
libicu.LibICU,
5455
swift.Swift,
5556
libdispatch.LibDispatch,
56-
libxml2.LibXML2]
57+
libxml2.LibXML2,
58+
zlib.Zlib]
5759

5860
@classmethod
5961
def is_nondarwin_only_build_product(cls):
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# swift_build_support/products/zlib.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 Zlib(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 zlib should be built
46+
"""
47+
return self.args.build_zlib
48+
49+
def should_test(self, host_target):
50+
"""should_test() -> Bool
51+
52+
Returns True if zlib 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
61+
If we're building zlib, you're going to need it
62+
"""
63+
return self.args.build_zlib
64+
65+
def install(self, host_target):
66+
"""
67+
Install zlib to the target location
68+
"""
69+
path = self.host_install_destdir(host_target)
70+
self.install_with_cmake(['install'], path)
71+
72+
def build(self, host_target):
73+
self.cmake_options.define('BUILD_SHARED_LIBS', 'NO')
74+
self.cmake_options.define('CMAKE_POSITION_INDEPENDENT_CODE', 'YES')
75+
76+
if self.args.zlib_build_variant is None:
77+
self.args.zlib_build_variant = "Release"
78+
self.cmake_options.define('CMAKE_BUILD_TYPE:STRING',
79+
self.args.zlib_build_variant)
80+
self.cmake_options.define('CMAKE_BUILD_TYPE', 'RELEASE')
81+
self.cmake_options.define('SKIP_INSTALL_FILES', 'YES')
82+
self.cmake_options.define('CMAKE_INSTALL_PREFIX', '/usr')
83+
84+
(platform, arch) = host_target.split('-')
85+
common_c_flags = ' '.join(self.common_cross_c_flags(platform, arch))
86+
self.cmake_options.define('CMAKE_C_FLAGS', common_c_flags)
87+
self.cmake_options.define('CMAKE_CXX_FLAGS', common_c_flags)
88+
89+
if host_target.startswith("macosx") or \
90+
host_target.startswith("iphone") or \
91+
host_target.startswith("appletv") or \
92+
host_target.startswith("watch"):
93+
toolchain_file = self.generate_darwin_toolchain_file(platform, arch)
94+
self.cmake_options.define('CMAKE_TOOLCHAIN_FILE:PATH', toolchain_file)
95+
elif platform == "linux":
96+
toolchain_file = self.generate_linux_toolchain_file(platform, arch)
97+
self.cmake_options.define('CMAKE_TOOLCHAIN_FILE:PATH', toolchain_file)
98+
self.build_with_cmake(["all"], self.args.zlib_build_variant, [])

0 commit comments

Comments
 (0)