├── .gitignore ├── .gn ├── BUILD.gn ├── lib1 ├── private.h ├── public.h ├── private.cpp ├── public.cpp └── BUILD.gn ├── lib2 ├── private.h ├── private.cpp ├── public.h ├── public.cpp └── BUILD.gn ├── main ├── BUILD.gn └── main.cpp ├── README.md ├── .travis.yml └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | out 2 | -------------------------------------------------------------------------------- /.gn: -------------------------------------------------------------------------------- 1 | buildconfig = "//build/BUILDCONFIG.gn" 2 | -------------------------------------------------------------------------------- /BUILD.gn: -------------------------------------------------------------------------------- 1 | group("executable") { 2 | deps = [ "//main" ] 3 | } 4 | -------------------------------------------------------------------------------- /lib1/private.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | extern void lib1_private(); 4 | -------------------------------------------------------------------------------- /lib1/public.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | extern void lib1_public(); 4 | -------------------------------------------------------------------------------- /lib1/private.cpp: -------------------------------------------------------------------------------- 1 | #include "private.h" 2 | 3 | void lib1_private() { 4 | } 5 | -------------------------------------------------------------------------------- /lib1/public.cpp: -------------------------------------------------------------------------------- 1 | #include "private.h" 2 | 3 | void lib1_public() 4 | { 5 | lib1_private(); 6 | } 7 | -------------------------------------------------------------------------------- /lib2/private.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Private { 4 | public: 5 | Private(); 6 | ~Private(); 7 | }; -------------------------------------------------------------------------------- /main/BUILD.gn: -------------------------------------------------------------------------------- 1 | executable("main") { 2 | sources = [ 3 | "main.cpp", 4 | ] 5 | 6 | deps = [ 7 | "//lib2", 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /lib2/private.cpp: -------------------------------------------------------------------------------- 1 | #include "private.h" 2 | #include "lib1/public.h" 3 | 4 | Private::Private() { 5 | lib1_public(); 6 | } 7 | 8 | Private::~Private() { 9 | } -------------------------------------------------------------------------------- /lib2/public.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Private; 4 | 5 | struct Public { 6 | Public(); 7 | ~Public(); 8 | 9 | private: 10 | Private* private_; 11 | }; -------------------------------------------------------------------------------- /lib2/public.cpp: -------------------------------------------------------------------------------- 1 | #include "public.h" 2 | #include "private.h" 3 | 4 | Public::Public() { 5 | private_ = new Private(); 6 | } 7 | 8 | Public::~Public() { 9 | delete private_; 10 | } 11 | -------------------------------------------------------------------------------- /lib1/BUILD.gn: -------------------------------------------------------------------------------- 1 | source_set("lib1") { 2 | sources = [ 3 | "private.cpp", 4 | "private.h", 5 | "public.cpp", 6 | "public.h", 7 | ] 8 | 9 | public = [ 10 | "public.h", 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /lib2/BUILD.gn: -------------------------------------------------------------------------------- 1 | source_set("lib2") { 2 | sources = [ 3 | "private.cpp", 4 | "private.h", 5 | "public.cpp", 6 | "public.h", 7 | ] 8 | 9 | public = [ 10 | "public.h", 11 | ] 12 | 13 | deps = [ 14 | "//lib1", 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /main/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "lib2/public.h" 4 | 5 | // Wrong! Can be detected by 'gn check' 6 | #include "lib2/private.h" 7 | 8 | // Wrong! Can be detected by 'gn check' 9 | #include "lib1/private.h" 10 | 11 | int main() 12 | { 13 | auto p = std::make_unique(); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/p47t/GN-demo.svg?branch=master)](https://travis-ci.org/p47t/GN-demo) 2 | 3 | ## What is GN? 4 | 5 | Take a look at [Using GN build](https://docs.google.com/presentation/d/15Zwb53JcncHfEwHpnG_PoIbbzQ3GQi_cpujYwbpcbZo/edit?usp=sharing) by Brett Wilson. 6 | 7 | ## Build steps 8 | 9 | $ gn gen out 10 | $ ninja -C out 11 | 12 | ## See it in action 13 | 14 | [![asciicast](https://asciinema.org/a/0VdrIZDVNi9Le4PKQWjthQEP9.png)](https://asciinema.org/a/0VdrIZDVNi9Le4PKQWjthQEP9) 15 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | 3 | before_install: 4 | - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test 5 | - sudo apt-get update 6 | 7 | install: 8 | # Install gcc5 9 | - sudo apt-get install -qq g++-5 10 | - sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 90 11 | 12 | # Install Ninja v1.8.2 13 | - wget -O ninja.zip https://github.com/ninja-build/ninja/releases/download/v1.8.2/ninja-linux.zip 14 | - unzip ninja.zip 15 | 16 | # Install latest GN 17 | - wget -O gn.zip https://chrome-infra-packages.appspot.com/dl/gn/gn/linux-amd64/+/latest 18 | - unzip gn.zip 19 | 20 | script: 21 | - ./gn gen -v out 22 | - ./ninja -v -C out 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Patrick Tsai 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | --------------------------------------------------------------------------------