-
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
Conversation
845b0d4
to
b1e00d2
Compare
This allows linking swift-corelibs-foundation to packages with flags defined by `pkg-config`, rather than hardcoded ones. There are a couple of structural changes as well, namely that `pkg-config` will now be executed during `configure` rather than later by `ninja`. This seems acceptable as it's how cmake and autoconf work, but means a reconfigure will be required if any transitive dependency of a package we depend on files changes. The other structural change is that `-lcurl` will be passed unconditionally on platforms without pkg-config support (technically the `pkg_config_required` variable set). This makes curl a harder dependency on those platforms, but that seems unavoidable given that it's the only implementation of `URLSession`.
@parkera can you kick off CI for this change? |
foundation.LDFLAGS += '-lcurl ' | ||
if Configuration.current.requires_pkg_config: | ||
pkg_config_dependencies = [ | ||
'icu-i18n', |
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.
swift_cflags += package.swiftc_flags | ||
else: | ||
foundation.CFLAGS += ''.join([ | ||
'-I${SYSROOT}/usr/include/curl ', |
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.
I mechanically moved this from the previous unconditional block; however I'm not sure it ever did anything given that CF headers include <curl/curl.h>
and this directory appears to contain curl.h
and friends, without subdirectories. It also seems to have been repeated at least 4 times - I've condensed 3 of those into this line but I'm unsure about the 4th in the FreeBSD config (the pkg-plist seems to suggest that it wouldn't be needed there either but I don't have a system to test on).
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't these get added via package.cflags
on line 89 above?
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.
This is the else block of Configuration.current.requires_pkg_config
, so these are hardcoded guess paths (moved from being unconditionally included on line 64-65 and other places). When we have pkg-config
there's no reason to include them as they'll be included automatically by pkg-config <package_name> --libs
and pkg-config <package_name> --cflags
respectively. More importantly, if the PKG_CONFIG_PATH
environment variable points to somewhere other than the system libraries and headers for these packages we won't consider them and will instead use the intended paths.
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.
Got it, thanks.
@swift-ci please test |
https://bugs.swift.org/browse/SR-5608 doesn't exist? |
@ianpartridge looks like the issue key is actually SR-5603, updated the title |
Thanks. I really like the look of this PR - thanks for working on it 👍 |
@spevans how does this look to you? |
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to remove all of these flags? -lswiftCore
and -ldl
should be added by the swift compiler and I am also pretty sure that the libswiftCore
already uses some math functions so -lm
is probably getting added somewhere lower down if needed. I dont think -ldl
is needed on FreeBSD anyway so a cleanup of these flags would be good.
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 are the flags that get passed to the build for the CoreFoundation C library, which includes <math.h>
and <dlfcn.h>
so I believe -lm
and -ldl
should remain here in the spirit of include-what-you-use. I'm not sure about -lswiftCore
as CoreFoundation doesn't appear to be importing any swift headers and swiftc should indeed be passing that flag, but maybe there is some magic I don't understand. I'll file a bug to follow up as I'd like to keep this change focused on the PR title.
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.
-lswiftCore
is actually added by the compiler for any swift program that is compiled. -ldl
is a dependancy of libswiftCore.so
so it gets picked up there. Math functions are also used by the stdlib and I think -lm
is auto added by the C compiler (the same a -lc
) since it is dependant on how a given C library is structured, ie if certain functions are broken out into other libraries
Overall this looks good. Being able to specify pkg-config for the other libraries will be useful if we need to build new versions of them. The only thing to check is that an external ICU still builds correctly. @kevints Could you run a local test build of swift and swift-corelibs-foundation with the You will need to download ICU57.1 http://site.icu-project.org/download/57#TOC-ICU4C-Download (I think 59.1 has some issues) Then untar it so that you have an |
@spevans hmm, tests don't seem to pass against my local build with
having a look at ldd it looks like both my system libicu (version 52) and the built icu (version 57) are both getting linked in but the 57 one is not found (since it isn't copied to the library runpath which is $ORIGIN/../lib/swift/linux, this might be a race between install and test invocation).
This seems in line with what I'd expect having read through the foundation build - it unconditionally invokes pkg-config for icu, which will find the system one. This change doesn't change anything about that so I suspect this may have been broken for a while, if it ever worked at all (looking through the buildbot presets there doesn't appear to be CI for building on Linux with |
@kevints No worries, I'll take a look at the ICU stuff as I did it originally. What version of linux are you using? |
@spevans saw those issues on Ubuntu 14.04 |
@spevans modulo those ICU issues does this change look good to you otherwise? |
@kevints Yes this change looks ok to me. Im taking a look at the ICU issues but I'll deal with that separately - I think its because libxml2 is also dependant on ICU hence you seeing 2 versions. I'll also look at cleaning up the linker flags, again that can be done as a separate PR. |
@kevints I tested this PR whilst also building an external ICU and it was ok. I think the problem you saw may have been due to old config in the build directory - I did a clean build/test and it was ok. The 2 versions is because ICU is built with versioned symbols and libxml2 uses the system ICU, that will need to be solved in the future. |
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.
overall looks reasonable to me
@swift-ci please test and merge |
This allows linking swift-corelibs-foundation to packages with flags
defined by
pkg-config
, rather than hardcoded ones. There are a coupleof structural changes as well, namely that
pkg-config
will now beexecuted during
configure
rather than later byninja
. This seemsacceptable as it's how cmake and autoconf work, but means a reconfigure
will be required if any transitive dependency of a package we depend on changes.
The other structural change is that
-lcurl
will be passedunconditionally on platforms without pkg-config support (technically the
pkg_config_required
variable set). This makes curl a harder dependencyon those platforms, but that seems unavoidable given that it's the only
implementation of
URLSession
.