Xcode project generator for gn available now

1,109 views
Skip to first unread message

Sylvain Defresne

unread,
May 17, 2016, 3:38:20 AM5/17/16
to gn-dev
Hi,

With revision 6ee04b5ce4, generation of Xcode workspace and project is now available in gn. Similarly to Visual Studio, "gn gen" can be run with "--ide=xcode" option to have Xcode files generated.

As "gen" command prepares the build for a single configuration, only that given configuration is available. The solution is named "all.xcworkspace" and located in the root output directory. Project files are generated to build all executable targets (without any scheme so you may be prompted by Xcode to autogenerate schemes if the number of target is large, you can also use "--filters" option to limit which targets are generated in the project).

Code browsing, indexation, building and debugging from Xcode should work. If you want to pass extra parameters to ninja, you can use the "--ninja-extra-args" option (e.g. "--ninja-extra-args=-j1000" is recommended if you want to use goma).

Enjoy!
-- Sylvain

Dirk Pranke

unread,
May 17, 2016, 12:06:55 PM5/17/16
to Sylvain Defresne, gn-dev
Nice!

matej...@gmail.com

unread,
Jun 7, 2016, 6:23:42 PM6/7/16
to gn-dev
Hi Sylvain,

thanks for your work on this! I noticed that the generator is broken in current master though, it seems that unlike FilePath.Extension(), FindExtension returns extension without ".".

So IsSourceFileForIndexing always returns false and extension mapping doesn't work either.

-Matt

darkt...@gmail.com

unread,
Aug 5, 2016, 4:38:41 PM8/5/16
to gn-dev, matej...@gmail.com
Hi,

Thanks for working on this, it's very useful.

In the context of Chromium, I managed to generated the workspace, building content shell works just fine however after a long indexing time (which is ok considering the number of files) I can't get the code browsing to work by that I mean having Xcode to be able to parse correctly .h, .cc and .cpp files so that one can jump headers using cmd + click, navigate between methods using cmd + click or even using the "Jump to Definition" feature. Is this supposed to work? Quick Open works fine btw.

Setup : chromium master as of today
Xcode 7.3.1 on El Capitan
GN args : is_debug = false is_component_build = true enable_stripping = false
I used the filter function as well of gn with --filters=//content/*

Thanks.

BTW https://chromium.googlesource.com/chromium/src/+/master/docs/mac_build_instructions.md#Using-Xcode_Ninja-Hybrid probably needs an update (I can do it after I got everything working).

darkt...@gmail.com

unread,
Aug 5, 2016, 5:02:23 PM8/5/16
to gn-dev, matej...@gmail.com, darkt...@gmail.com
On Friday, August 5, 2016 at 1:38:41 PM UTC-7, darkt...@gmail.com wrote:
> Hi,
>
> Thanks for working on this, it's very useful.
>
> In the context of Chromium, I managed to generated the workspace, building content shell works just fine however after a long indexing time (which is ok considering the number of files) I can't get the code browsing to work by that I mean having Xcode to be able to parse correctly .h, .cc and .cpp files so that one can jump headers using cmd + click, navigate between methods using cmd + click or even using the "Jump to Definition" feature. Is this supposed to work? Quick Open works fine btw.

It seems that it only happens on Blink source files. I can navigate correctly in content/. Any ideas?

Sylvain Defresne

unread,
Aug 5, 2016, 7:34:47 PM8/5/16
to darkt...@gmail.com, gn-dev, matej...@gmail.com
Jump to file only work if the #include path is relative to src/ not to a subdirectory. So if the file is included as third_party/WebKit/public/... it would work, but if the include is relative it won't.
-- Sylvain

Alexis Ménard

unread,
Aug 5, 2016, 7:38:50 PM8/5/16
to Sylvain Defresne, gn-dev
Hi,

That would explain also why the parsing would not work as Xcode probably can't resolve the includes from within Blink. So do you think of a suggestion on how one could work within Blink inside Xcode and enjoy the completion/code navigation/...?

Thanks.


Sylvain Defresne

unread,
Aug 5, 2016, 7:45:10 PM8/5/16
to Alexis Ménard, gn-dev
AFAIK, only cmd+click is broken by the relative includes, so cmd+shift+o to jump to file/symbol should still work (as Xcode is able to parse the files). It may be confused by macros (as the preprocessor defines coming from the command-line are not available to Xcode project).

If you want to do better, I think you would need to generate proper Xcode project instead of an hybrid project using ninja to build (i.e. have different targets in Xcode, with proper include directories, ...) like we used to do with gyp. Or at least projects that are closer to proper Xcode projects. But then you may run into the issue that cause Xcode to be poor IDE to work on Chromium (last time I checked, Xcode was unable to work properly with an Xcode project generated with gyp, due to the size of the project).
-- Sylvain

Alexis Menard

unread,
Aug 5, 2016, 7:53:47 PM8/5/16
to Sylvain Defresne, gn-dev
Hi,


On Friday, August 5, 2016, Sylvain Defresne <sdef...@google.com> wrote:
AFAIK, only cmd+click is broken by the relative includes, so cmd+shift+o to jump to file/symbol should still work (as Xcode is able to parse the files). It may be confused by macros (as the preprocessor defines coming from the command-line are not available to Xcode project).

Well I don't even have the syntax highlighting (beside keywords) in Blink whereas other parts of Chromium are fine. I can't jump to Symbol/Definition either.
 


If you want to do better, I think you would need to generate proper Xcode project instead of an hybrid project using ninja to build (i.e. have different targets in Xcode, with proper include directories, ...) like we used to do with gyp. Or at least projects that are closer to proper Xcode projects. But then you may run into the issue that cause Xcode to be poor IDE to work on Chromium (last time I checked, Xcode was unable to work properly with an Xcode project generated with gyp, due to the size of the project).
-- Sylvain

Yes that's unfortunate, Visual Studio with Funnel extension can let me hack anywhere by only loading the targets I want. But Windows is extremely slow to compile.

At the end of the day, building in the IDE is not really what I need but proper code navigation, auto completion and visual debugger is probably the top features.

Anyway thanks for the answers.

Sylvain Defresne

unread,
Aug 5, 2016, 8:02:11 PM8/5/16
to Alexis Menard, gn-dev
It may be possible to improve the current position regarding the generated Xcode project. I mostly developed and tested the Xcode project generation while working on Chrome on iOS project (which does not use Blink). Any patch that improve the situation would be welcomed.

Regarding the syntax highlighting, I guess this is again because the file you open do use relative imports (i.e. when parsing the .cc file, Xcode is unable to find the include, so does not know about the types, and cannot do syntax highlighting correctly). You can try to configure the include paths in Xcode to add the ones that are missing and see if the situation improves. If it does, then you can check at the difference between the project before and after your changes, and see how you can maybe inform gn on how to generate the fixed version of the project from the information it has available.
-- Sylvain

matej...@gmail.com

unread,
Aug 5, 2016, 11:08:06 PM8/5/16
to gn-dev, matej...@gmail.com, darkt...@gmail.com
Hi,

with latest gn that supports --ide=json you can try my experimental xcode generator.

https://github.com/knopp/gn-project-generators/

it generates separate xcode target for each indexed gn target with proper include dirs, defines, precopiled headers, etc. set, so things like relative includes should work.

that said, i haven't tried it with blink (though i did try it with default chromium checkout). I'd still suggest to use --filter= , though the filtering will also include all dependencies (recursively) so even that might not be enough.

the python generator is naturally going to be slower than the default on written in c++, using pypy helps significantly.

-Matej

ihorka...@gmail.com

unread,
Mar 3, 2020, 7:24:47 AM3/3/20
to gn-dev
Hi Sylvain,
Do you know how to add BUILD.gn files to the XCode project too via an gn generator?

Sylvain Defresne

unread,
Mar 3, 2020, 7:35:12 AM3/3/20
to ihorka...@gmail.com, gn-dev
Hi,

This is something that is frequently requested but not supported. I've created a bug to track this at https://bugs.chromium.org/p/gn/issues/detail?id=152.

Cheers,
-- Sylvain
Reply all
Reply to author
Forward
0 new messages