I've actually prepared some draft implementation for this and was in progress to make some proposal too :)
We've supported swift in our project for about 2-3 years and we have 3 apps currently in app store built with gn, with extensive use of swift (10k+ .swift files, hundreds of modules). Some thoughts on proposal:
1. Although invoking frontend looks promising, as it looks like it will fit well in ninja/gn model, it is not usable in practice, we've abandoned that approach in favour of using swift-driver almost instantly. Disadvantages of using frontend directly:
- Broken incremental compilation, as every change, even in implementation of private function will trigger recompilation of whole module and all dependant modules.
- Parsing time grows quadratically, as every frontend invocation has to parse all files (this is fixed by batch mode in driver, that is hard to implement in gn).
- There are actually 3 different compilation mods, supported in driver: incremental, whole-module and single-threaded whole-module. Although all of them can be achieved by frontend invocation manually, it is not trivial to do. Using driver, on the other hand, almost entirely eliminates the differences, with exception that single-threaded whole-module will output only one .o file per module.
- Frontend API is considered as unstable and is not recommended for use by swift folks.
- Frontend has a very hard time working with relative paths
Disadvantages of using swift-driver:
- swift-driver needs special json file that contains dictionary that maps input files to output (object file, partial module, and some other files).
- It is harder to explain in gn that tool, depending on mode, can output multiple or only one object files.
In my draft implementation I've created two tools actually, for incremental mode and for single-object mode. First generates output-file-map.json and expects one object file per input and second doesn't generate json and expects one .o file.
2. swift can export objc header file with objc-compatible public interface, that is essential feature for compatibility with objc. As it outputs from swift invocation, gn needs to know about that output, so support is needed on gn level.
3. module cache is actually not the desired way to propagate interfaces, it can be done more explicitly with -I flag with path where .swiftmodule is stored. This way it muuch more robust to compilation flakiness.
4. Does swift really needs special target type? As I understand, there is no problem with putting .swift files to source_set. Even thought compilation model is slightly different, in the end it's just old good .o files that can be linked.
You should now have permission to comment.
Yes, thank you.
Context is that Chrome on iOS team does not want to be painted in a corner if required iOS API are only made available in Swift in future version of the SDK, so we want to have the option to build .swift file and link them into an application without having to add support in a hurry.
-- Sylvain
Hi,
Will you give us comment permission?
Also I'm curious background of this proposal.
Based on investigation on how .swift files can be built from command-line (see
document), I suggest adding a new type of target to gn and two new tools to add support to build .swift files.
They would be used like this:
swift_module("foo") { output_name = "Foo" # Will be reused as the name of the module. sources = [ "File1.swift", "File2.swift", ] bridge_header = "Foo-Bridging-Header.h" }
toolchain("ios_clang") { tool("swift_compile") { command = "swift -frontend -c -primary-file {{source}} -o {{output}} ..." partial_module_output = "..." outputs = [ "..." ] } tool("swift_merge") { command = "swift -frontend -merge-modules ..." module_output = "..." } } |
Regards,
-- Sylvain
--
To unsubscribe from this group and stop receiving emails from it, send an email to gn-dev+un...@chromium.org.
--
To unsubscribe from this group and stop receiving emails from it, send an email to gn-dev+un...@chromium.org.
-- To unsubscribe from this group and stop receiving emails from it, send an email to gn-dev+un...@chromium.org.
To unsubscribe from this group and stop receiving emails from it, send an email to