facebookarchive / xcbuild

Xcode-compatible build tool.
Other
2k stars 190 forks source link

Support building mixed targets #237

Open vhbit opened 7 years ago

vhbit commented 7 years ago

Steps to reproduce:

git clone https://github.com/Quick/Nimble
cd Nimble
xcbuild -project Nimble.xcodeproj -scheme "Nimble-iOS" -configuration "Debug" -sdk "iphonesimulator"

at some point it fails with:

Nimble/Sources/NimbleObjectiveC/NMBStringify.m:2:9: fatal error: 'Nimble/Nimble-Swift.h' file not found

My guess would be that in case of mixed code Swift module has to be built first. xcbuild was built from 9754643ae0c237593292af22b7332110268edb62

onhachoe commented 7 years ago

I'm aware of this exact issue, and working on a fix right now, PR for it should come pretty soon.

onhachoe commented 7 years ago

The relevant PR is merged, closing this issue.

vhbit commented 7 years ago

Tested on master - the issue is still present. It seems xcbuild misses some steps and also too aggressive in parallelising them.

First of all, it usually fails a couple of times when starting compiling Swift sources, it seems it happens because not all headers are copied/processed? In Xcode there are 2 actions shown before Swift compilation: "Write auxiliary files" and "Create product structure".

If I run build again and again at some point it goes through and builds Swift module but still fails in Obj-C part with the same error as before fatal error: 'Nimble/Nimble-Swift.h' file not found.

From the quick look the difference with Xcode build is that the latter after building Swift does the following for all architectures:

Ditto /Users/vhbit/Library/Developer/Xcode/DerivedData/Nimble-geamnsituxelwdbwhhulkgurwaku/Build/Products/Debug-iphonesimulator/Nimble.framework/Headers/Nimble-Swift.h /Users/vhbit/Library/Developer/Xcode/DerivedData/Nimble-geamnsituxelwdbwhhulkgurwaku/Build/Intermediates/Nimble.build/Debug-iphonesimulator/Nimble-iOS.build/Objects-normal/i386/Nimble-Swift.h
    cd /Users/vhbit/projects/external/Nimble
    export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /usr/bin/ditto -rsrc /Users/vhbit/Library/Developer/Xcode/DerivedData/Nimble-geamnsituxelwdbwhhulkgurwaku/Build/Intermediates/Nimble.build/Debug-iphonesimulator/Nimble-iOS.build/Objects-normal/i386/Nimble-Swift.h /Users/vhbit/Library/Developer/Xcode/DerivedData/Nimble-geamnsituxelwdbwhhulkgurwaku/Build/Products/Debug-iphonesimulator/Nimble.framework/Headers/Nimble-Swift.h

But doing that manually still doesn't help, more likely that's related to a different clang invocation. Here is what is missing in xcbuild invocation:

-gmodules
-fbuild-session-file=/Users/vhbit/Library/Developer/Xcode/DerivedData/ModuleCache/Session.modulevalidation
-fmodules-validate-once-per-build-session
-Xclang -fmodule-implementation-of
-Xclang Nimble
-I/Users/vhbit/Library/Developer/Xcode/DerivedData/Nimble-geamnsituxelwdbwhhulkgurwaku/Build/Intermediates/Nimble.build/Debug-iphonesimulator/Nimble-iOS.build/Nimble-all-non-framework-target-headers.hmap
-ivfsoverlay /Users/vhbit/Library/Developer/Xcode/DerivedData/Nimble-geamnsituxelwdbwhhulkgurwaku/Build/Intermediates/Nimble.build/all-product-headers.yaml
--serialize-diagnostics /Users/vhbit/Library/Developer/Xcode/DerivedData/Nimble-geamnsituxelwdbwhhulkgurwaku/Build/Intermediates/Nimble.build/Debug-iphonesimulator/Nimble-iOS.build/Objects-normal/i386/NMBStringify.dia

(if it'll be helpful, here is full list of args)

I had no time to play more yet, but it seems that missing ditto + -ivfsoverlay are real show stoppers for Obj-C part.