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
swift: init at 3.1 #22098
swift: init at 3.1 #22098
Conversation
For the curious, working on a variant of this using the 3.0.2 release on this branch: https://github.com/dtzWill/nixpkgs/tree/feature/swift-3.0.2 Don't even know if that branch builds yet though, but thought I'd share :). |
3.0.2 needs multiple patches to avoid crashing during compilation, I've patched a few in that branch but giving up on making that work for the time being. Hopefully 3.1+ is suitable and has an official release soon enough :). |
cp -r ${sources.llbuild} llbuild | ||
cp -r ${sources.pm} swiftpm | ||
cp -r ${sources.xctest} swift-corelibs-xctest | ||
cp -r ${sources.foundation} swift-corelibs-foundation |
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.
Does the build automatically build all this stuff? I'm surprised to see these going in.
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.
Yep! What's built is described by the preset we're using, which is a modified version of what they use on the linux buildbots:
https://github.com/NixOS/nixpkgs/pull/22098/files#diff-207758b47bdae6fde307317858e26f47R715
(which references the mixin_linux_installation
preset: https://github.com/NixOS/nixpkgs/pull/22098/files#diff-207758b47bdae6fde307317858e26f47R681).
It's possible we can break these apart eventually but I don't think it would be easy or even worth it--AFAICT the components are all very much meant to be built/tested together.
Also this does take a while to build... :).
How much remains to be done on this PR before it's suitable for merging to master? |
I think a good start would be having one or more people express interest and confirm this builds and works for them/their use cases. Any takers? :) |
I've been using it over the last few days to do some intro-to-swift exercises, and can confirm that the basic functionality does seem to work: |
@benley great to hear! Thanks for reporting the bit about 'import Foundation', I can confirm that it doesn't work here either. This appears to be a known issue upstream: https://bugs.swift.org/browse/SR-3794 One of the proposed workarounds there is to add -I$swift/lib/swift/clang/include, which fixes it for me:
(your hash might be different; I forget which tree I installed swift from) Not sure if this is something they need to fix or if it would make sense to auto-add it with a wrapper or some source patching. |
squasshed + rebased, updated to 3.1-2017-03-13. |
Works for me 👍 We should probably bump to 3.1 final and ship it |
Final has been released? Woohoo! Pushed updated expression, still rebuilding to test locally though :). |
Looks good! One nitpick though: is there a way we can get around build-presets.ini? I see the file might also be in utils/build-presets.ini, can we just use that? |
Yeah, that build-presets.ini seems like a maintenance nightmare, especially if upstream evolves the format or options available. If we're making changes to it, can we just bundle a patch to the upstream file to make it clearer what we care about and what doesn't matter? Apart from that it looks good |
Sure thing, I'll take care of this later today (meetings and such :)). |
sha256 = "0820mx1ghfnk4p5595r1f313y1699jwi61zghfbwak5wgwgy7n4x"; | ||
}; | ||
llvm = fetch { | ||
repo = "swift-llvm"; |
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.
Do you know if it really needs its own custom llvm or if it can use our pre-existing packages? I fear that we'll be missing patches and it'll reach out to all sorts of impure locations as a result.
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 was unable to convince their build scripts to use an external LLVM. I believe their versions of these components are very similar but haven't tried sorting out differences (especially since I don't think they're based on a particular fixed release). Without more insight into the differences I'd be reluctant to use anything other than their vendor'd LLVM due to concerns about possible subtle behavioral differences from other "Swift 3.1" implementations.
That said, even breaking this huge build into pieces would be awfully nice :).
|
||
buildPhase = ''${builder}''; | ||
|
||
dontStrip = true; |
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 not (just curious)?
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 believe I set this early after looking at this bit from Arch's AUR PKGBUILD for Swift 3.02 and never revisited seeing what broke with it disabled. I'm not sure how to test whether this is still needed, although I can at least confirm whether stripping severely breaks things :).
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.
Not a problem, was just curious. I'll probably tinker with it a bit to get a macOS version running after you push this.
|
||
doCheck = false; | ||
|
||
buildPhase = ''${builder}''; |
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.
''${builder}''
should be equivalent to builder
installPhase = '' | ||
mkdir -p $out | ||
|
||
# Extract the generated tarball into the store |
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.
Does the build process have to generate a tarball? Feels kind of convoluted, but I guess such is life sometimes 😄
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 wouldn't go so far as to say it /has/ to generate a tarball, but it's the best I could find for installing all the bits neatly. Unfortunately given the very long build time this is a bit tainted by being satisfied with what works vs trying other things. I agree it's unfortunate, for sure.
buildInputs = [ clang ]; | ||
|
||
configurePhase = '' | ||
export CC=clang |
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'd actually use the clangStdenv
here, since that'll get you proper llvm-flavored libraries like libc++ and so on, and will be more standard I think.
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.
Hmm. So it's a bit tricky I think, here's what I know/why things are why this way:
- libblocksruntime isn't C++ (so I don't think it matters if we use libc++)
- their build script checks for gcc, clang, then 'cc' but later uses the name it found to determine what CFLAGS to use. Using a clang-based stdenv doesn't actually make clang available by that name (just like linux stdenv doesn't make gcc available by that name), so clang would need to be a buildInput or this behavior patched around.
- It turns out that hardening flags add -O2 which I think may make the previous point moot but I don't think that should be relied upon.
I'm not saying this is the best solution, but I'm not sure it's better to use clangStdenv. Thoughts? Incidentally I tried using clangStdenv just now and the resulting archive was bit-identical but that doesn't really mean much just a fun fact :).
(Thank you very much for the comments and review, there were more dark corners in this than I remembered! Working to address them now..) |
I can squash in a bit, but thought I'd make it easier to spot the new changes for now. Experimentally removed 'dontStrip', we'll see how this goes (go go gadget compiler!). If it doesn't break my use of Swift I'm thinking that we ship this way--if and when someone encounters breakage we can add the 'dontStrip' workaround. Sound good? |
Related: SourceKit apparently builds on Linux but currently requires building Swift /twice/: Just an FYI so if anyone wants to add it AFAIK it shouldn't be difficult just a lot more building, at least until they do the necessary build refactoring upstream. |
@dtzWill cool, I think the "just FYI" kind of thing is more likely to get noticed as a comment in the expression source though. Otherwise you just know someone will see the expression and try it out 😄 |
(the only thing I really care about is the .ini file at this point) |
Add dependency 'libblocksruntime'.
Added FYI to the expression per suggestion, everything else should be addressed in the latest commit! :) |
homepage = "https://github.com/apple/swift"; | ||
maintainers = with maintainers; [ jb55 dtzWill ]; | ||
license = licenses.asl20; | ||
platforms = platforms.linux; |
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.
Have you tried it on macOS?
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.
Nope! But since, for example, the current buildPhase explicitly refers to the linux build configuration I'm pretty sure it won't work :(. Hopefully it's not too much trouble to make it work on Darwin, but I really don't know.
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.
Okay I can look into it but this PR is definitely good to merge even without macOS
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.
Looks good to me!
Also add dependency 'libblocksruntime'.
#11463
Motivation for this change
Things done
(nix.useSandbox on NixOS,
or option
build-use-sandbox
innix.conf
on non-NixOS)
nix-shell -p nox --run "nox-review wip"
./result/bin/
)Review/testing/feedback requested!
Short-term TODO:
build-presets.ini
in the tree?Things to pay attention to, and other thoughts:
Misc notes:
swiftc
,swift-pm
, and the swift REPL seem to work in my limited testing.