Skip to content

Commit ef8c149

Browse files
committed
Add curl build product
Add libcurl as a build product. This is another piece required to build foundation in a freestanding configuration.
1 parent d718474 commit ef8c149

File tree

7 files changed

+169
-2
lines changed

7 files changed

+169
-2
lines changed

utils/build-script-impl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ components=(
267267
libicu
268268
libxml2
269269
zlib
270+
curl
270271
llbuild
271272
lldb
272273
llvm
@@ -2567,6 +2568,13 @@ for host in "${ALL_HOSTS[@]}"; do
25672568
)
25682569
fi
25692570

2571+
if [[ ! "${SKIP_BUILD_CURL}" ]]; then
2572+
BASE_INSTALL_DIR="$(get_host_install_destdir ${host})"
2573+
CURL_BUILD_ARGS=(
2574+
-DCURL_DIR="${BASE_INSTALL_DIR}/usr/lib/cmake/CURL"
2575+
)
2576+
fi
2577+
25702578
if [[ "${SKIP_CLEAN_FOUNDATION}" == "0" ]]
25712579
then
25722580
# The Swift project might have been changed, but CMake might
@@ -2597,6 +2605,8 @@ for host in "${ALL_HOSTS[@]}"; do
25972605

25982606
${ZLIB_BUILD_ARGS[@]}
25992607

2608+
${CURL_BUILD_ARGS[@]}
2609+
26002610
-DFOUNDATION_PATH_TO_LIBDISPATCH_SOURCE=${LIBDISPATCH_SOURCE_DIR}
26012611
-DFOUNDATION_PATH_TO_LIBDISPATCH_BUILD=$(build_directory ${host} libdispatch)
26022612
-Ddispatch_DIR=$(build_directory ${host} libdispatch)/cmake/modules

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ def _apply_default_arguments(args):
9696
if args.zlib_build_variant is None:
9797
args.zlib_build_variant = args.build_variant
9898

99+
if args.curl_build_variant is None:
100+
args.curl_build_variant = args.build_variant
101+
99102
# Assertions are enabled by default.
100103
if args.assertions is None:
101104
args.assertions = True
@@ -721,6 +724,9 @@ def create_argument_parser():
721724
option('--static-zlib', toggle_true('build_zlib'), default=False,
722725
help='build static zlib')
723726

727+
option('--static-curl', toggle_true('build_curl'), default=False,
728+
help='build static curl libraries')
729+
724730
option('--playgroundsupport', toggle_true('build_playgroundsupport'),
725731
help='build PlaygroundSupport')
726732
option('--install-playgroundsupport',
@@ -840,6 +846,10 @@ def create_argument_parser():
840846
const='Debug',
841847
help='build the Debug variant of zlib')
842848

849+
option('--debug-curl', store('curl_build_variant'),
850+
const='Debug',
851+
help='build the Debug variant of libcurl')
852+
843853
# -------------------------------------------------------------------------
844854
# Assertions group
845855

@@ -1276,6 +1286,8 @@ def create_argument_parser():
12761286
help='skip building libxml2')
12771287
option('--skip-build-zlib', toggle_false('build_zlib'),
12781288
help='skip building zlib')
1289+
option('--skip-build-curl', toggle_false('build_curl'),
1290+
help='skip building curl')
12791291

12801292
# We need to list --skip-test-swift explicitly because otherwise argparse
12811293
# will auto-expand arguments like --skip-test-swift to the only known
@@ -1356,6 +1368,7 @@ def create_argument_parser():
13561368
/icu (optional)
13571369
/libxml2 (optional)
13581370
/zlib (optional)
1371+
/curl (optional)
13591372
13601373
SWIFT_BUILD_ROOT: a directory in which to create out-of-tree builds.
13611374
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
@@ -68,6 +68,7 @@
6868
'build_libicu': False,
6969
'build_libxml2': False,
7070
'build_zlib': False,
71+
'build_curl': False,
7172
'build_linux': True,
7273
'build_llbuild': False,
7374
'build_lldb': False,
@@ -185,6 +186,7 @@
185186
'libicu_build_variant': 'Debug',
186187
'libxml2_build_variant': 'Debug',
187188
'zlib_build_variant': 'Debug',
189+
'curl_build_variant': 'Debug',
188190
'bootstrapping_mode': None,
189191
'lit_args': '-sv',
190192
'llbuild_assertions': True,
@@ -435,6 +437,7 @@ class BuildScriptImplOption(_BaseOption):
435437
SetOption('--debug-libicu', dest='libicu_build_variant', value='Debug'),
436438
SetOption('--debug-libxml2', dest='libxml2_build_variant', value='Debug'),
437439
SetOption('--debug-zlib', dest='zlib_build_variant', value='Debug'),
440+
SetOption('--debug-curl', dest='curl_build_variant', value='Debug'),
438441
SetOption('--debug-lldb', dest='lldb_build_variant', value='Debug'),
439442
SetOption('--lldb-build-with-xcode', dest='lldb_build_with_xcode',
440443
value='1'),
@@ -568,6 +571,7 @@ class BuildScriptImplOption(_BaseOption):
568571
EnableOption('--libicu', dest='build_libicu'),
569572
EnableOption('--static-libxml2', dest='build_libxml2'),
570573
EnableOption('--static-zlib', dest='build_zlib'),
574+
EnableOption('--static-curl', dest='build_curl'),
571575
EnableOption('--indexstore-db', dest='build_indexstoredb'),
572576
EnableOption('--test-indexstore-db-sanitize-all',
573577
dest='test_indexstoredb_sanitize_all'),
@@ -673,6 +677,7 @@ class BuildScriptImplOption(_BaseOption):
673677
dest='build_clang_tools_extra'),
674678
DisableOption('--skip-build-libxml2', dest='build_libxml2'),
675679
DisableOption('--skip-build-zlib', dest='build_zlib'),
680+
DisableOption('--skip-build-curl', dest='build_curl'),
676681

677682
ChoicesOption('--compiler-vendor',
678683
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
@@ -256,7 +256,8 @@ def convert_to_impl_arguments(self):
256256
(args.build_libdispatch, "libdispatch"),
257257
(args.build_libicu, "libicu"),
258258
(args.build_libxml2, 'libxml2'),
259-
(args.build_zlib, 'zlib')
259+
(args.build_zlib, 'zlib'),
260+
(args.build_curl, 'curl')
260261
]
261262
for (should_build, string_name) in conditional_subproject_configs:
262263
if not should_build and not self.args.infer_dependencies:
@@ -549,6 +550,9 @@ def compute_product_pipelines(self):
549550
builder.add_product(products.zlib.Zlib,
550551
is_enabled=self.args.build_zlib)
551552

553+
builder.add_product(products.curl.LibCurl,
554+
is_enabled=self.args.build_curl)
555+
552556
# Begin a build-script-impl pipeline for handling the compiler toolchain
553557
# and a subset of the tools that we build. We build these in this manner
554558
# 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
@@ -13,6 +13,7 @@
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
@@ -50,6 +51,7 @@
5051
'LibICU',
5152
'LibXML2',
5253
'Zlib',
54+
'LibCurl',
5355
'LLBuild',
5456
'LLDB',
5557
'LLVM',
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# swift_build_support/products/curl.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 zlib
15+
16+
17+
class LibCurl(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 product_source_name(cls):
40+
"""product_source_name -> Bool
41+
42+
returns 'curl'
43+
"""
44+
return "curl"
45+
46+
@classmethod
47+
def get_dependencies(cls):
48+
return [zlib.Zlib]
49+
50+
def should_build(self, host_target):
51+
"""should_build() -> Bool
52+
53+
Return True if curl should be built
54+
"""
55+
return self.args.build_curl
56+
57+
def should_test(self, host_target):
58+
"""should_test() -> Bool
59+
60+
Returns True if curl should be tested.
61+
Currently is set to false
62+
"""
63+
return False
64+
65+
def should_install(self, host_target):
66+
"""should_install() -> Bool
67+
68+
Returns True
69+
If we're building curl, you're going to need it
70+
"""
71+
return self.args.build_curl
72+
73+
def install(self, host_target):
74+
"""
75+
Install curl to the target location
76+
"""
77+
path = self.host_install_destdir(host_target)
78+
self.install_with_cmake(['install'], path)
79+
80+
def build(self, host_target):
81+
self.cmake_options.define('BUILD_SHARED_LIBS', 'NO')
82+
self.cmake_options.define('CMAKE_POSITION_INDEPENDENT_CODE', 'YES')
83+
84+
if self.args.curl_build_variant is None:
85+
self.args.curl_build_variant = 'Release'
86+
self.cmake_options.define('CMAKE_BUILD_TYPE:STRING',
87+
self.args.curl_build_variant)
88+
self.cmake_options.define('CMAKE_INSTALL_LIBDIR', 'lib')
89+
self.cmake_options.define('CMAKE_INSTALL_PREFIX', '/usr')
90+
self.cmake_options.define('BUILD_CURL_EXE', 'NO')
91+
self.cmake_options.define('CMAKE_USE_OPENSSL', 'NO')
92+
self.cmake_options.define('CURL_CA_PATH', 'none')
93+
self.cmake_options.define('CMAKE_USE_SCHANNEL', 'NO')
94+
self.cmake_options.define('CMAKE_USE_LIBSSH2', 'NO')
95+
self.cmake_options.define('HAVE_POLL_FINE', 'NO')
96+
self.cmake_options.define('CURL_DISABLE_LDAP', 'YES')
97+
self.cmake_options.define('CURL_DISABLE_LDAPS', 'YES')
98+
self.cmake_options.define('CURL_DISABLE_TELNET', 'YES')
99+
self.cmake_options.define('CURL_DISABLE_DICT', 'YES')
100+
self.cmake_options.define('CURL_DISABLE_FILE', 'YES')
101+
self.cmake_options.define('CURL_DISABLE_TFTP', 'YES')
102+
self.cmake_options.define('CURL_DISABLE_RTSP', 'YES')
103+
self.cmake_options.define('CURL_DISABLE_PROXY', 'YES')
104+
self.cmake_options.define('CURL_DISABLE_POP3', 'YES')
105+
self.cmake_options.define('CURL_DISABLE_IMAP', 'YES')
106+
self.cmake_options.define('CURL_DISABLE_SMTP', 'YES')
107+
self.cmake_options.define('CURL_DISABLE_GOPHER', 'YES')
108+
self.cmake_options.define('CURL_ZLIB', 'YES')
109+
self.cmake_options.define('ENABLE_UNIX_SOCKETS', 'NO')
110+
self.cmake_options.define('ENABLE_THREADED_RESOLVER', 'NO')
111+
112+
(platform, arch) = host_target.split('-')
113+
common_c_flags = ' '.join(self.common_cross_c_flags(platform, arch))
114+
self.cmake_options.define('CMAKE_C_FLAGS', common_c_flags)
115+
self.cmake_options.define('CMAKE_CXX_FLAGS', common_c_flags)
116+
117+
if host_target.startswith("macosx") or \
118+
host_target.startswith("iphone") or \
119+
host_target.startswith("appletv") or \
120+
host_target.startswith("watch"):
121+
toolchain_file = self.generate_darwin_toolchain_file(platform, arch)
122+
self.cmake_options.define('CMAKE_TOOLCHAIN_FILE:PATH', toolchain_file)
123+
elif platform == "linux":
124+
toolchain_file = self.generate_linux_toolchain_file(platform, arch)
125+
self.cmake_options.define('CMAKE_TOOLCHAIN_FILE:PATH', toolchain_file)
126+
127+
if self.args.build_zlib:
128+
# If we're building zlib, make cmake search in the built toolchain
129+
toolchain_path = self.host_install_destdir(host_target)
130+
self.cmake_options.define('CMAKE_FIND_ROOT_PATH', toolchain_path)
131+
self.build_with_cmake(['libcurl'], self.args.curl_build_variant, [])

utils/swift_build_support/swift_build_support/products/foundation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# ----------------------------------------------------------------------------
1212

1313
from . import cmark
14+
from . import curl
1415
from . import libcxx
1516
from . import libdispatch
1617
from . import libicu
@@ -55,7 +56,8 @@ def get_dependencies(cls):
5556
swift.Swift,
5657
libdispatch.LibDispatch,
5758
libxml2.LibXML2,
58-
zlib.Zlib]
59+
zlib.Zlib,
60+
curl.LibCurl]
5961

6062
@classmethod
6163
def is_nondarwin_only_build_product(cls):

0 commit comments

Comments
 (0)