Skip to content

[linux] Switch to GN, and remove Makefiles #261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,6 @@

matrix:
include:
- os: linux
dist: xenial
language: cpp
before_install:
- sudo apt-get update
install:
- build/ci/linux/install_dependencies
- build/ci/install_flutter $TRAVIS_BUILD_DIR/..
before_script:
- export PATH=$PATH:$TRAVIS_BUILD_DIR/../flutter/bin:$TRAVIS_BUILD_DIR/bin
script:
- make -C example/linux_fde

- os: linux
dist: xenial
language: cpp
Expand All @@ -39,7 +26,7 @@ matrix:
before_script:
- export PATH=$PATH:$TRAVIS_BUILD_DIR/bin
script:
- make -C example/linux_fde USE_GN=1
- make -C example/linux_fde

- os: osx
language: objective-c
Expand Down
66 changes: 17 additions & 49 deletions example/linux_fde/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,31 @@ FLUTTER_EMBEDDER_LIB_DIR=$(FDE_ROOT)/library/linux
PLUGINS_DIR=$(FDE_ROOT)/plugins
TOOLS_DIR=$(FDE_ROOT)/tools
FLUTTER_DIR=$(shell $(TOOLS_DIR)/flutter_location)
GN_OUT_DIR=$(FDE_ROOT)/out

# Libraries
FLUTTER_EMBEDDER_LIB_NAME=flutter_embedder
FLUTTER_EMBEDDER_LIB=$(FLUTTER_EMBEDDER_LIB_DIR)/lib$(FLUTTER_EMBEDDER_LIB_NAME).so
FLUTTER_EMBEDDER_LIB=$(GN_OUT_DIR)/lib$(FLUTTER_EMBEDDER_LIB_NAME).so

FLUTTER_ENGINE_LIB_NAME=flutter_engine
FLUTTER_ENGINE_LIB=$(FLUTTER_EMBEDDER_LIB_DIR)/lib$(FLUTTER_ENGINE_LIB_NAME).so
FLUTTER_ENGINE_LIB=$(GN_OUT_DIR)/lib$(FLUTTER_ENGINE_LIB_NAME).so

PLUGIN_LIB_NAME_PREFIX=flutter_embedder_
PLUGIN_LIBS=$(foreach plugin,$(PLUGIN_NAMES)\
,$(PLUGINS_DIR)/$(plugin)/linux/lib$(PLUGIN_LIB_NAME_PREFIX)$(plugin).so)
,$(GN_OUT_DIR)/lib$(PLUGIN_LIB_NAME_PREFIX)$(plugin).so)

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

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

# Tools
BUILD_ASSETS_BIN=$(TOOLS_DIR)/build_flutter_assets
FLUTTER_BIN=$(FLUTTER_DIR)/bin/flutter
GN_WRAPPER=$(TOOLS_DIR)/gn_dart
NINJA_BIN=ninja

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

# Overrides for the optional GN build.
ifdef USE_GN
GN_OUT_DIR=$(FDE_ROOT)/out

# The GN build places all libraries at the top level of the output directory.
FLUTTER_EMBEDDER_LIB=$(GN_OUT_DIR)/lib$(FLUTTER_EMBEDDER_LIB_NAME).so
FLUTTER_ENGINE_LIB=$(GN_OUT_DIR)/lib$(FLUTTER_ENGINE_LIB_NAME).so
PLUGIN_LIBS=$(foreach plugin,$(PLUGIN_NAMES)\
,$(GN_OUT_DIR)/lib$(PLUGIN_LIB_NAME_PREFIX)$(plugin).so)

# The GN build places all published headers in a top-level include/.
INCLUDE_DIRS=$(GN_OUT_DIR)/include

# Override LIBRARY_DIRS since it's used for controlling the external build.
LIBRARY_DIRS=$(GN_OUT_DIR)

# Additional tools
GN_WRAPPER=$(TOOLS_DIR)/gn_dart
NINJA_BIN=ninja
endif

# Build settings
CXX=g++ -std=c++14
CXXFLAGS.release=-DNDEBUG
CXXFLAGS=-Wall -Werror $(shell pkg-config --cflags jsoncpp glfw3) \
$(CXXFLAGS.$(BUILD))
CPPFLAGS=$(patsubst %,-I%,$(INCLUDE_DIRS))
ifdef USE_GN
CPPFLAGS+=-DUSE_FLATTENED_INCLUDES
endif
LDFLAGS=-L$(OUT_LIB_DIR) \
$(shell pkg-config --libs jsoncpp glfw3) \
-l$(FLUTTER_EMBEDDER_LIB_NAME) \
Expand All @@ -124,27 +103,16 @@ $(BIN_OUT): $(SOURCES) $(ALL_LIBS_OUT)
mkdir -p $(@D)
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(SOURCES) $(LDFLAGS) -o $@

# Depedency directories are used as phony targets to invoke their builds.
ifdef USE_GN
.PHONY: $(LIBRARY_DIRS)
$(LIBRARY_DIRS):
$(GN_WRAPPER) gen $(GN_OUT_DIR)
.PHONY: gnbuild
gnbuild: $(GN_OUT_DIR)
$(NINJA_BIN) -C $(GN_OUT_DIR) $(FLUTTER_EMBEDDER_LIB_NAME) $(PLUGIN_NAMES)
else
.PHONY: $(LIBRARY_DIRS)
$(LIBRARY_DIRS):
$(MAKE) -C $@ $(MAKECMDGOALS)

# Enforce relative ordering. This prevents accidentally building the targets
# in parallel in the event that someone supplies the -j flag to `make`.
# TODO: Fix this in the plugin builds so that it's not necessary at this layer.
$(PLUGIN_DIRS): $(FLUTTER_EMBEDDER_LIB_DIR)
endif

# Require that all the library builds run for anything depending on the
# libraries, but use order-only so that the phony build targets don't trigger
# rebuilds of all dependencies every time.
$(ALL_LIBS): | $(LIBRARY_DIRS)

$(GN_OUT_DIR):
$(GN_WRAPPER) gen $(GN_OUT_DIR)

# Run the GN build for anything depending on the libraries, but use order-only
# so that it doesn't trigger rebuilds of all dependencies every time.
$(ALL_LIBS): | gnbuild

# This is slightly inefficient in that it copies all libraries if any of them
# changes, but is far simpler than setting up individual rules for each library.
Expand Down
7 changes: 1 addition & 6 deletions example/linux_fde/flutter_embedder_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,8 @@

#include <color_panel/color_panel_plugin.h>
#include <file_chooser/file_chooser_plugin.h>
#include <menubar/menubar_plugin.h>

#ifdef USE_FLATTENED_INCLUDES
#include <flutter_desktop_embedding/flutter_window_controller.h>
#else
#include <flutter_desktop_embedding/glfw/flutter_window_controller.h>
#endif
#include <menubar/menubar_plugin.h>

namespace {

Expand Down
23 changes: 8 additions & 15 deletions library/GN.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
# Using GN

If you are building on Linux or Windows, you can use GN instead of Make or
Visual Studio.

This is currently optional and is under evaluation, but in the future it may
become the build system used on all platforms.
If you are building on Windows, you can use GN instead of Visual Studio.

## Dependencies

### Tools

In addition to the normal dependencies, you will need to install:
* [ninja](https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages)
* [gn](https://gn.googlesource.com/gn/)

Ensure that both binaries are in your path.

### Windows
### Path setup

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

Windows requires jsoncpp to be downloaded to
### jsoncpp

jsoncpp must be manually downloaded to
`third_party/jsoncpp\src`. Use
`tools/dart_tools/bin/fetch_jsoncpp.dart` to automatically download `jsoncpp`
as shown below:
Expand Down Expand Up @@ -70,19 +70,12 @@ $ ninja -C out

### Example

#### Linux

To use the GN build for the depedencies of the example application, when
running `make` for the example add `USE_GN=1` to the end of the command.

#### Windows

Building the example with GN is not currently supported. Follow the [Visual
Studio example build instructions](../example/README.md) to build the example
app.

## Feedback

If you encounter issues with the GN build, please test with Make or Visual
If you encounter issues with the GN build, please test with Visual
Studio before filing a bug so that the report can include whether the issue is
specific to GN, or a general build issue.
32 changes: 25 additions & 7 deletions library/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ the ICU data from the Flutter engine.

#### Dependencies

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

You will need to install the build tools if you don't already have them:
* [ninja](https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages)
* [gn](https://gn.googlesource.com/gn/)

Ensure that both binaries are in your path.

#### Using the Library

Run `make` under `linux/`, then link `libflutter_embedder.so` into your
binary. See
[flutter_window_controller.h](include/flutter_desktop_embedding/glfw/flutter_window_controller.h)
for details on calling into the library.
To build the library, run the following at the root of this repository:

```
$ tools/gn_dart gen out
$ ninja -C out flutter_embedder
```
Subsequent builds only require the `ninja` step, as the build will automatically
re-run GN generation if necessary.

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

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

### macOS

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

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

_Note: There is also a [GN build](GN.md) available as an alternative._

## Caveats

* There is currently no versioning system for coordinating the version
Expand Down
9 changes: 9 additions & 0 deletions library/include/flutter_desktop_embedding/glfw/embedder.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
#include <string>
#include <vector>

// On Linux, the header output is always flattened; on Windows the GN build
// is still optional. Once GN is required on Windows, eliminate this and just
// use FLUTTER_DESKTOP_EMBEDDING_IMPL to control include paths.
#ifndef USE_FLATTENED_INCLUDES
#if !defined(FLUTTER_DESKTOP_EMBEDDING_IMPL) && defined(__linux__)
#define USE_FLATTENED_INCLUDES 1
#endif
#endif

#ifdef USE_FLATTENED_INCLUDES
#include "fde_export.h"
#else
Expand Down
3 changes: 0 additions & 3 deletions library/linux/.gitignore

This file was deleted.

63 changes: 0 additions & 63 deletions library/linux/Makefile

This file was deleted.

22 changes: 13 additions & 9 deletions plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,27 @@ Build the Xcode project under the macos diretory for each plugin you
want to use, then link the resulting framework in your project.

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

```objc
[myFlutterViewController addPlugin:[[FLEColorPanelPlugin alloc] init]];
[FLEFileChooserPlugin registerWithRegistrar:
[myFlutterViewController registrarForPlugin:"FLEFileChooserPlugin"]];
```

### Linux

Run `make` in the `linux` directory for each plugin you want to use, then
link the resulting library in your application.
Run `ninja -C out` at the root of the repository to build all plugins, then
link the libraries for the plugins you want into your application. As with the
library build, `out/` and `out/include/` will contain all the files you need.

After creating your Flutter window, call AddPlugin with an instance of each
plugin you want to use. For instance:
After creating your Flutter window controller, call your plugin's registrar
method. For instance:

```cpp
AddPlugin(window,
std::make_unique<plugins_color_panel::ColorPanelPlugin>());
plugins_color_panel::ColorPanelPlugin::RegisterWithRegistrar(
my_flutter_controller.GetRegistrarForPlugin(
"plugins_color_panel::ColorPanelPlugin"));
```

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

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

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