-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Use pkg-config to find libxml2 and libcurl on Linux [SR-5603] #1152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,8 @@ | |
|
||
swift_cflags = ['-DDEPLOYMENT_RUNTIME_SWIFT'] | ||
if Configuration.current.target.sdk == OSType.Linux: | ||
foundation.CFLAGS = '`${PKG_CONFIG} icu-uc icu-i18n --cflags-only-I` -DDEPLOYMENT_TARGET_LINUX -D_GNU_SOURCE -DCF_CHARACTERSET_DATA_DIR="CoreFoundation/CharacterSets"' | ||
foundation.LDFLAGS = '${SWIFT_USE_LINKER} -Wl,@./CoreFoundation/linux.ld -lswiftGlibc `${PKG_CONFIG} icu-uc icu-i18n --libs` -Wl,-Bsymbolic ' | ||
foundation.CFLAGS = '-DDEPLOYMENT_TARGET_LINUX -D_GNU_SOURCE -DCF_CHARACTERSET_DATA_DIR="CoreFoundation/CharacterSets"' | ||
foundation.LDFLAGS = '${SWIFT_USE_LINKER} -Wl,@./CoreFoundation/linux.ld -lswiftGlibc -Wl,-Bsymbolic ' | ||
Configuration.current.requires_pkg_config = True | ||
elif Configuration.current.target.sdk == OSType.FreeBSD: | ||
foundation.CFLAGS = '-DDEPLOYMENT_TARGET_FREEBSD -I/usr/local/include -I/usr/local/include/libxml2 -I/usr/local/include/curl ' | ||
|
@@ -61,35 +61,55 @@ | |
'-Wno-unused-variable', | ||
'-Wno-int-conversion', | ||
'-Wno-unused-function', | ||
'-I${SYSROOT}/usr/include/libxml2', | ||
'-I${SYSROOT}/usr/include/curl', | ||
'-I./', | ||
]) | ||
|
||
swift_cflags += [ | ||
'-I${BUILD_DIR}/Foundation/usr/lib/swift', | ||
'-I${SYSROOT}/usr/include/libxml2', | ||
'-I${SYSROOT}/usr/include/curl' | ||
] | ||
|
||
if "XCTEST_BUILD_DIR" in Configuration.current.variables: | ||
swift_cflags += [ | ||
'-I${XCTEST_BUILD_DIR}', | ||
'-L${XCTEST_BUILD_DIR}', | ||
'-I${SYSROOT}/usr/include/libxml2', | ||
'-I${SYSROOT}/usr/include/curl' | ||
] | ||
|
||
triple = Configuration.current.target.triple | ||
if triple.find("linux") != -1: | ||
foundation.LDFLAGS += '-lcurl ' | ||
if Configuration.current.requires_pkg_config: | ||
pkg_config_dependencies = [ | ||
'icu-i18n', | ||
'icu-uc', | ||
'libcurl', | ||
'libxml-2.0', | ||
] | ||
for package_name in pkg_config_dependencies: | ||
try: | ||
package = PkgConfig(package_name) | ||
except PkgConfig.Error as e: | ||
sys.exit("pkg-config error for package {}: {}".format(package_name, e)) | ||
foundation.CFLAGS += ' {} '.format(' '.join(package.cflags)) | ||
foundation.LDFLAGS += ' {} '.format(' '.join(package.ldflags)) | ||
swift_cflags += package.swiftc_flags | ||
else: | ||
foundation.CFLAGS += ''.join([ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why don't these get added via There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the else block of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it, thanks. |
||
'-I${SYSROOT}/usr/include/curl ', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mechanically moved this from the previous unconditional block; however I'm not sure it ever did anything given that CF headers include |
||
'-I${SYSROOT}/usr/include/libxml2 ', | ||
]) | ||
foundation.LDFLAGS += ''.join([ | ||
'-lcurl ', | ||
'-lxml2 ', | ||
]) | ||
swift_cflags += ''.join([ | ||
'-I${SYSROOT}/usr/include/curl ', | ||
'-I${SYSROOT}/usr/include/libxml2 ', | ||
]) | ||
|
||
triple = Configuration.current.target.triple | ||
if triple == "armv7-none-linux-androideabi": | ||
foundation.LDFLAGS += '-llog ' | ||
else: | ||
foundation.LDFLAGS += '-lpthread ' | ||
|
||
foundation.LDFLAGS += '-ldl -lm -lswiftCore -lxml2 ' | ||
foundation.LDFLAGS += '-ldl -lm -lswiftCore ' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to remove all of these flags? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are the flags that get passed to the build for the CoreFoundation C library, which includes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
# Configure use of Dispatch in CoreFoundation and Foundation if libdispatch is being built | ||
if "LIBDISPATCH_SOURCE_DIR" in Configuration.current.variables: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,9 @@ | |
"config", | ||
"path", | ||
"phases", | ||
"pkg_config", | ||
"product", | ||
"script", | ||
"target", | ||
"workspace", | ||
] | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from __future__ import print_function | ||
|
||
import shlex | ||
import subprocess | ||
import sys | ||
|
||
from .config import Configuration | ||
|
||
|
||
class PkgConfig(object): | ||
class Error(Exception): | ||
"""Raised when information could not be obtained from pkg-config.""" | ||
|
||
def __init__(self, package_name): | ||
"""Query pkg-config for information about a package. | ||
|
||
:type package_name: str | ||
:param package_name: The name of the package to query. | ||
:raises PkgConfig.Error: When a call to pkg-config fails. | ||
""" | ||
self.package_name = package_name | ||
self._cflags = self._call("--cflags") | ||
self._cflags_only_I = self._call("--cflags-only-I") | ||
self._cflags_only_other = self._call("--cflags-only-other") | ||
self._libs = self._call("--libs") | ||
self._libs_only_l = self._call("--libs-only-l") | ||
self._libs_only_L = self._call("--libs-only-L") | ||
self._libs_only_other = self._call("--libs-only-other") | ||
|
||
def _call(self, *pkg_config_args): | ||
try: | ||
cmd = [Configuration.current.pkg_config] + list(pkg_config_args) + [self.package_name] | ||
print("Executing command '{}'".format(cmd), file=sys.stderr) | ||
return shlex.split(subprocess.check_output(cmd)) | ||
except subprocess.CalledProcessError as e: | ||
raise self.Error("pkg-config exited with error code {}".format(e.returncode)) | ||
|
||
@property | ||
def swiftc_flags(self): | ||
"""Flags for this package in a format suitable for passing to `swiftc`. | ||
|
||
:rtype: list[str] | ||
""" | ||
return ( | ||
["-Xcc {}".format(s) for s in self._cflags_only_other] | ||
+ ["-Xlinker {}".format(s) for s in self._libs_only_other] | ||
+ self._cflags_only_I | ||
+ self._libs_only_L | ||
+ self._libs_only_l) | ||
|
||
@property | ||
def cflags(self): | ||
"""CFLAGS for this package. | ||
|
||
:rtype: list[str] | ||
""" | ||
return self._cflags | ||
|
||
@property | ||
def ldflags(self): | ||
"""LDFLAGS for this package. | ||
|
||
:rtype: list[str] | ||
""" | ||
return self._libs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should probably specify a minimum package version (probably from Ubuntu 14.04 as it's the oldest supported target), WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no harm in doing that, I guess. Currently we link against the system libicu which has plusses and minuses.