Skip to content

Commit 607c4f2

Browse files
[linux] Switch to GN, and remove Makefiles
For the library and plugins, switch to GN as the only supported build system on Linux. GN will be used for the library in the flutter/engine repository, so the make build will no longer be necessary; remove it now to avoid the overhead of maintaining an extra build system until the transition happens. The example continues to use Make in order to show typical usage of the library, and the color_panel plugin has an example makefile (updated to reflect the use of GN to build the library) as an example/starting point for someone making a plugin outside of the FDE repository. Addresses google#114 for Linux.
1 parent 96e92a9 commit 607c4f2

File tree

18 files changed

+122
-285
lines changed

18 files changed

+122
-285
lines changed

.travis.yml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,6 @@
1414

1515
matrix:
1616
include:
17-
- os: linux
18-
dist: xenial
19-
language: cpp
20-
before_install:
21-
- sudo apt-get update
22-
install:
23-
- build/ci/linux/install_dependencies
24-
- build/ci/install_flutter $TRAVIS_BUILD_DIR/..
25-
before_script:
26-
- export PATH=$PATH:$TRAVIS_BUILD_DIR/../flutter/bin:$TRAVIS_BUILD_DIR/bin
27-
script:
28-
- make -C example/linux_fde
29-
3017
- os: linux
3118
dist: xenial
3219
language: cpp
@@ -39,7 +26,7 @@ matrix:
3926
before_script:
4027
- export PATH=$PATH:$TRAVIS_BUILD_DIR/bin
4128
script:
42-
- make -C example/linux_fde USE_GN=1
29+
- make -C example/linux_fde
4330

4431
- os: osx
4532
language: objective-c

example/linux_fde/Makefile

Lines changed: 17 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,31 @@ FLUTTER_EMBEDDER_LIB_DIR=$(FDE_ROOT)/library/linux
3737
PLUGINS_DIR=$(FDE_ROOT)/plugins
3838
TOOLS_DIR=$(FDE_ROOT)/tools
3939
FLUTTER_DIR=$(shell $(TOOLS_DIR)/flutter_location)
40+
GN_OUT_DIR=$(FDE_ROOT)/out
4041

4142
# Libraries
4243
FLUTTER_EMBEDDER_LIB_NAME=flutter_embedder
43-
FLUTTER_EMBEDDER_LIB=$(FLUTTER_EMBEDDER_LIB_DIR)/lib$(FLUTTER_EMBEDDER_LIB_NAME).so
44+
FLUTTER_EMBEDDER_LIB=$(GN_OUT_DIR)/lib$(FLUTTER_EMBEDDER_LIB_NAME).so
4445

4546
FLUTTER_ENGINE_LIB_NAME=flutter_engine
46-
FLUTTER_ENGINE_LIB=$(FLUTTER_EMBEDDER_LIB_DIR)/lib$(FLUTTER_ENGINE_LIB_NAME).so
47+
FLUTTER_ENGINE_LIB=$(GN_OUT_DIR)/lib$(FLUTTER_ENGINE_LIB_NAME).so
4748

4849
PLUGIN_LIB_NAME_PREFIX=flutter_embedder_
4950
PLUGIN_LIBS=$(foreach plugin,$(PLUGIN_NAMES)\
50-
,$(PLUGINS_DIR)/$(plugin)/linux/lib$(PLUGIN_LIB_NAME_PREFIX)$(plugin).so)
51+
,$(GN_OUT_DIR)/lib$(PLUGIN_LIB_NAME_PREFIX)$(plugin).so)
5152

5253
ALL_LIBS=$(FLUTTER_EMBEDDER_LIB) $(FLUTTER_ENGINE_LIB) $(PLUGIN_LIBS)
5354

5455
# Headers
5556
PLUGIN_DIRS=$(patsubst %,$(PLUGINS_DIR)/%/linux,$(PLUGIN_NAMES))
56-
LIBRARY_DIRS=$(FLUTTER_EMBEDDER_LIB_DIR) $(PLUGIN_DIRS)
57-
INCLUDE_DIRS=$(patsubst %,%/include,$(LIBRARY_DIRS)) $(FDE_ROOT)/library/include
57+
# The GN build places all published headers in a top-level include/.
58+
INCLUDE_DIRS=$(GN_OUT_DIR)/include
5859

5960
# Tools
6061
BUILD_ASSETS_BIN=$(TOOLS_DIR)/build_flutter_assets
6162
FLUTTER_BIN=$(FLUTTER_DIR)/bin/flutter
63+
GN_WRAPPER=$(TOOLS_DIR)/gn_dart
64+
NINJA_BIN=ninja
6265

6366
# Resources
6467
ICU_DATA_NAME=icudtl.dat
@@ -75,36 +78,12 @@ BIN_OUT=$(OUT_DIR)/flutter_embedder_example
7578
ICU_DATA_OUT=$(OUT_DATA_DIR)/$(ICU_DATA_NAME)
7679
ALL_LIBS_OUT=$(foreach lib,$(ALL_LIBS),$(OUT_LIB_DIR)/$(notdir $(lib)))
7780

78-
# Overrides for the optional GN build.
79-
ifdef USE_GN
80-
GN_OUT_DIR=$(FDE_ROOT)/out
81-
82-
# The GN build places all libraries at the top level of the output directory.
83-
FLUTTER_EMBEDDER_LIB=$(GN_OUT_DIR)/lib$(FLUTTER_EMBEDDER_LIB_NAME).so
84-
FLUTTER_ENGINE_LIB=$(GN_OUT_DIR)/lib$(FLUTTER_ENGINE_LIB_NAME).so
85-
PLUGIN_LIBS=$(foreach plugin,$(PLUGIN_NAMES)\
86-
,$(GN_OUT_DIR)/lib$(PLUGIN_LIB_NAME_PREFIX)$(plugin).so)
87-
88-
# The GN build places all published headers in a top-level include/.
89-
INCLUDE_DIRS=$(GN_OUT_DIR)/include
90-
91-
# Override LIBRARY_DIRS since it's used for controlling the external build.
92-
LIBRARY_DIRS=$(GN_OUT_DIR)
93-
94-
# Additional tools
95-
GN_WRAPPER=$(TOOLS_DIR)/gn_dart
96-
NINJA_BIN=ninja
97-
endif
98-
9981
# Build settings
10082
CXX=g++ -std=c++14
10183
CXXFLAGS.release=-DNDEBUG
10284
CXXFLAGS=-Wall -Werror $(shell pkg-config --cflags jsoncpp glfw3) \
10385
$(CXXFLAGS.$(BUILD))
10486
CPPFLAGS=$(patsubst %,-I%,$(INCLUDE_DIRS))
105-
ifdef USE_GN
106-
CPPFLAGS+=-DUSE_FLATTENED_INCLUDES
107-
endif
10887
LDFLAGS=-L$(OUT_LIB_DIR) \
10988
$(shell pkg-config --libs jsoncpp glfw3) \
11089
-l$(FLUTTER_EMBEDDER_LIB_NAME) \
@@ -124,27 +103,16 @@ $(BIN_OUT): $(SOURCES) $(ALL_LIBS_OUT)
124103
mkdir -p $(@D)
125104
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(SOURCES) $(LDFLAGS) -o $@
126105

127-
# Depedency directories are used as phony targets to invoke their builds.
128-
ifdef USE_GN
129-
.PHONY: $(LIBRARY_DIRS)
130-
$(LIBRARY_DIRS):
131-
$(GN_WRAPPER) gen $(GN_OUT_DIR)
106+
.PHONY: gnbuild
107+
gnbuild: $(GN_OUT_DIR)
132108
$(NINJA_BIN) -C $(GN_OUT_DIR) $(FLUTTER_EMBEDDER_LIB_NAME) $(PLUGIN_NAMES)
133-
else
134-
.PHONY: $(LIBRARY_DIRS)
135-
$(LIBRARY_DIRS):
136-
$(MAKE) -C $@ $(MAKECMDGOALS)
137-
138-
# Enforce relative ordering. This prevents accidentally building the targets
139-
# in parallel in the event that someone supplies the -j flag to `make`.
140-
# TODO: Fix this in the plugin builds so that it's not necessary at this layer.
141-
$(PLUGIN_DIRS): $(FLUTTER_EMBEDDER_LIB_DIR)
142-
endif
143-
144-
# Require that all the library builds run for anything depending on the
145-
# libraries, but use order-only so that the phony build targets don't trigger
146-
# rebuilds of all dependencies every time.
147-
$(ALL_LIBS): | $(LIBRARY_DIRS)
109+
110+
$(GN_OUT_DIR):
111+
$(GN_WRAPPER) gen $(GN_OUT_DIR)
112+
113+
# Run the GN build for anything depending on the libraries, but use order-only
114+
# so that it doesn't trigger rebuilds of all dependencies every time.
115+
$(ALL_LIBS): | gnbuild
148116

149117
# This is slightly inefficient in that it copies all libraries if any of them
150118
# changes, but is far simpler than setting up individual rules for each library.

example/linux_fde/flutter_embedder_example.cc

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,8 @@
2121

2222
#include <color_panel/color_panel_plugin.h>
2323
#include <file_chooser/file_chooser_plugin.h>
24-
#include <menubar/menubar_plugin.h>
25-
26-
#ifdef USE_FLATTENED_INCLUDES
2724
#include <flutter_desktop_embedding/flutter_window_controller.h>
28-
#else
29-
#include <flutter_desktop_embedding/glfw/flutter_window_controller.h>
30-
#endif
25+
#include <menubar/menubar_plugin.h>
3126

3227
namespace {
3328

library/GN.md

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
# Using GN
22

3-
If you are building on Linux or Windows, you can use GN instead of Make or
4-
Visual Studio.
5-
6-
This is currently optional and is under evaluation, but in the future it may
7-
become the build system used on all platforms.
3+
If you are building on Windows, you can use GN instead of Visual Studio.
84

95
## Dependencies
106

7+
### Tools
8+
119
In addition to the normal dependencies, you will need to install:
1210
* [ninja](https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages)
1311
* [gn](https://gn.googlesource.com/gn/)
1412

1513
Ensure that both binaries are in your path.
1614

17-
### Windows
15+
### Path setup
1816

1917
Windows also requires the 64 bit compiler, linker and setup scripts to be in
2018
your path. They are found under:
@@ -29,7 +27,9 @@ e.g.:
2927
> C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build
3028
```
3129

32-
Windows requires jsoncpp to be downloaded to
30+
### jsoncpp
31+
32+
jsoncpp must be manually downloaded to
3333
`library/windows/third_party/jsoncpp`. Use
3434
`tools/dart_tools/bin/fetch_jsoncpp.dart` to automatically download `jsoncpp`
3535
as shown below:
@@ -74,19 +74,12 @@ $ ninja -C out
7474

7575
### Example
7676

77-
#### Linux
78-
79-
To use the GN build for the depedencies of the example application, when
80-
running `make` for the example add `USE_GN=1` to the end of the command.
81-
82-
#### Windows
83-
8477
Building the example with GN is not currently supported. Follow the [Visual
8578
Studio example build instructions](../example/README.md) to build the example
8679
app.
8780

8881
## Feedback
8982

90-
If you encounter issues with the GN build, please test with Make or Visual
83+
If you encounter issues with the GN build, please test with Visual
9184
Studio before filing a bug so that the report can include whether the issue is
9285
specific to GN, or a general build issue.

library/README.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ the ICU data from the Flutter engine.
3737

3838
#### Dependencies
3939

40-
First you will need to install the relevant dependencies:
40+
First you will need to install the relevant library dependencies:
4141
* GLFW3
4242
* GTK 3
4343
* jsoncpp
@@ -52,16 +52,32 @@ $ sudo apt-get install libglfw3-dev libepoxy-dev libjsoncpp-dev libgtk-3-dev \
5252
libx11-dev pkg-config
5353
```
5454

55+
You will need to install the build tools if you don't already have them:
56+
* [ninja](https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages)
57+
* [gn](https://gn.googlesource.com/gn/)
58+
59+
Ensure that both binaries are in your path.
60+
5561
#### Using the Library
5662

57-
Run `make` under `linux/`, then link `libflutter_embedder.so` into your
58-
binary. See
59-
[flutter_window_controller.h](include/flutter_desktop_embedding/glfw/flutter_window_controller.h)
60-
for details on calling into the library.
63+
To build the library, run the following at the root of this repository:
64+
65+
```
66+
$ tools/gn_dart gen out
67+
$ ninja -C out flutter_embedder
68+
```
69+
Subsequent builds only require the `ninja` step, as the build will automatically
70+
re-run GN generation if necessary.
6171

62-
You will also need to link `libflutter_engine.so` into your binary.
72+
The build results will be in the top-level `out/` directory. You will need to
73+
link `libflutter_embedder.so` and `libflutter_engine.so` into your binary.
74+
Public headers will be in `out/include/`; you should point dependent
75+
builds at that location rather than the `include/` directories in the
76+
source tree.
6377

64-
_Note: There is also a [GN build](GN.md) available as an alternative to Make._
78+
See
79+
[flutter_window_controller.h](include/flutter_desktop_embedding/glfw/flutter_window_controller.h)
80+
for details on calling into the library.
6581

6682
### macOS
6783

@@ -103,6 +119,8 @@ the `flutter_engine.dll`, and if using a dynamic library
103119

104120
The output files are located in `bin\x64\$(Configuration)\GLFW Library\`.
105121

122+
_Note: There is also a [GN build](GN.md) available as an alternative._
123+
106124
## Caveats
107125

108126
* There is currently no versioning system for coordinating the version

library/include/flutter_desktop_embedding/glfw/embedder.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@
1919
#include <string>
2020
#include <vector>
2121

22+
// On Linux, the header output is always flattened; on Windows the GN build
23+
// is still optional. Once GN is required on Windows, eliminate this and just
24+
// use FLUTTER_DESKTOP_EMBEDDING_IMPL to control include paths.
25+
#ifndef USE_FLATTENED_INCLUDES
26+
#if !defined(FLUTTER_DESKTOP_EMBEDDING_IMPL) && defined(__linux__)
27+
#define USE_FLATTENED_INCLUDES 1
28+
#endif
29+
#endif
30+
2231
#ifdef USE_FLATTENED_INCLUDES
2332
#include "fde_export.h"
2433
#include "plugin_registrar.h"

library/linux/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

library/linux/Makefile

Lines changed: 0 additions & 63 deletions
This file was deleted.

plugins/README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,27 @@ Build the Xcode project under the macos diretory for each plugin you
3232
want to use, then link the resulting framework in your project.
3333

3434
When you set up your FLEViewController, before calling `launchEngine...`,
35-
call `-addPlugin:` with an instance of each plugin you want to use. For
35+
call `-registerWithRegistrar:` on each plugin you want to use. For
3636
instance:
3737

3838
```objc
39-
[myFlutterViewController addPlugin:[[FLEColorPanelPlugin alloc] init]];
39+
[FLEFileChooserPlugin registerWithRegistrar:
40+
[myFlutterViewController registrarForPlugin:"FLEFileChooserPlugin"]];
4041
```
4142
4243
### Linux
4344
44-
Run `make` in the `linux` directory for each plugin you want to use, then
45-
link the resulting library in your application.
45+
Run `ninja -C out` at the root of the repository to build all plugins, then
46+
link the libraries for the plugins you want into your application. As with the
47+
library build, `out/` and `out/include/` will contain all the files you need.
4648
47-
After creating your Flutter window, call AddPlugin with an instance of each
48-
plugin you want to use. For instance:
49+
After creating your Flutter window controller, call your plugin's registrar
50+
method. For instance:
4951
5052
```cpp
51-
AddPlugin(window,
52-
std::make_unique<plugins_color_panel::ColorPanelPlugin>());
53+
plugins_color_panel::ColorPanelPlugin::RegisterWithRegistrar(
54+
my_flutter_controller.GetRegistrarForPlugin(
55+
"plugins_color_panel::ColorPanelPlugin"));
5356
```
5457

5558
### Example Application
@@ -63,7 +66,8 @@ optional plugins on the Dart side.
6366
## Writing your own plugins
6467

6568
You can easily create local packages following the model of plugins here to
66-
use in your own projects.
69+
use in your own projects. In particular, the color_panel plugin has examples
70+
of typical platform builds for plugins.
6771

6872
If you think they would be generally useful, feel free to submit a pull request
6973
and they could potentially be folded into this repository. In the future, as

0 commit comments

Comments
 (0)