Skip to content

Commit 1007405

Browse files
authored
Initial Linux GN build (#149)
Adds an experimental GN-based build as an alternative to the Make-based build on Linux. The example application does not use GN for its own build since it is intended to serve as an example of using the embedding library, so it continues to use the more common Make as clients are unlikely to be using GN. See issue #114
1 parent ae4451d commit 1007405

File tree

22 files changed

+891
-0
lines changed

22 files changed

+891
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
out/
12
.DS_Store

.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
buildconfig = "//build/BUILDCONFIG.gn"

BUILD.gn

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
group("gn_all") {
16+
deps = [
17+
"//library:flutter_embedder",
18+
"//plugins/color_panel:color_panel",
19+
"//plugins/file_chooser:file_chooser",
20+
"//plugins/menubar:menubar",
21+
]
22+
}

build/BUILD.gn

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
config("defaults") {
16+
cflags = [
17+
"-std=c++14",
18+
"-Wall",
19+
"-Werror",
20+
"-pthread",
21+
]
22+
include_dirs = [
23+
"//"
24+
]
25+
}
26+
27+
config("shared_library_defaults") {
28+
cflags = [
29+
"-shared",
30+
"-fPIC",
31+
]
32+
}

build/BUILDCONFIG.gn

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
set_default_toolchain("//third_party/chromium/build/toolchain:gcc")
16+
17+
set_defaults("executable") {
18+
configs = [ "//build:defaults" ]
19+
}
20+
set_defaults("static_library") {
21+
configs = [ "//build:defaults" ]
22+
}
23+
set_defaults("shared_library") {
24+
configs = [ "//build:defaults", "//build:shared_library_defaults" ]
25+
}
26+
set_defaults("published_shared_library") {
27+
configs = [ "//build:defaults", "//build:shared_library_defaults" ]
28+
}
29+
30+
if (host_os == "linux") {
31+
is_linux = true
32+
is_mac = false
33+
is_win = false
34+
} else if (host_os == "mac") {
35+
is_linux = false
36+
is_mac = true
37+
is_win = false
38+
} else if (host_os == "win") {
39+
is_linux = false
40+
is_mac = false
41+
is_win = true
42+
}

build/flutter.gni

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
declare_args() {
16+
# The path to the Flutter tree to use for any Flutter operations or assets.
17+
# If empty, assumes a directory called 'flutter' that is a sibling of this
18+
# repository (like tools/flutter_location; this duplication avoids shelling
19+
# out).
20+
flutter_tree_path = rebase_path("../../flutter")
21+
}

build/linux/config/BUILD.gn

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("//third_party/chromium/build/config/linux/pkg_config.gni")
16+
17+
pkg_config("gtk3") {
18+
packages = [ "gtk+-3.0" ]
19+
}
20+
21+
pkg_config("epoxy") {
22+
packages = [ "epoxy" ]
23+
}
24+
25+
pkg_config("x11") {
26+
packages = [ "x11" ]
27+
}
28+
29+
pkg_config("jsoncpp") {
30+
packages = [ "jsoncpp" ]
31+
}

build/packaging.gni

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Puts the public headers of the invoker in public_header_subdir
16+
# under the top-level include/ directory in the build output.
17+
#
18+
# This is intended to make consuming public headers of all the libraries built
19+
# by GN easy for outside build systems on Linux, by requiring only a single
20+
# include directory.
21+
if (is_linux) {
22+
template("copy_includes") {
23+
copy(target_name) {
24+
assert(defined(invoker.sources),
25+
"|sources| must be provided for copy_includes.")
26+
forward_variables_from(invoker, [ "deps", "sources", "subdir" ])
27+
output_dir = "$root_out_dir/include"
28+
if (defined(subdir)) {
29+
output_dir = "$output_dir/$subdir"
30+
}
31+
outputs = [ "$output_dir/{{source_file_part}}"]
32+
}
33+
}
34+
}
35+
36+
# An abstraction for a shared library with associated headers that is intended
37+
# to be consumed from the build output.
38+
#
39+
# On Linux, this performs a copy_includes in addition to building the library.
40+
template("published_shared_library") {
41+
template_target_name = target_name
42+
43+
if (is_linux) {
44+
copy_includes("_publish_${template_target_name}_headers") {
45+
sources = invoker.public
46+
subdir = invoker.public_header_subdir
47+
}
48+
49+
shared_library(template_target_name) {
50+
forward_variables_from(invoker, "*")
51+
assert(defined(public),
52+
"|public| must be provided for published_shared_library.")
53+
54+
if (!defined(deps)) {
55+
deps = []
56+
}
57+
deps += [ ":_publish_${template_target_name}_headers" ]
58+
}
59+
}
60+
}

example/linux/Makefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,29 @@ BIN_OUT=$(OUT_DIR)/flutter_embedder_example
5858
ICU_DATA_OUT=$(OUT_DATA_DIR)/$(ICU_DATA_NAME)
5959
ALL_LIBS_OUT=$(foreach lib,$(ALL_LIBS),$(OUT_LIB_DIR)/$(notdir $(lib)))
6060

61+
# Overrides for the optional GN build.
62+
ifdef USE_GN
63+
GN_OUT_DIR=$(PROJECT_ROOT)/out
64+
# Use GN's out dir even though this isn't a GN build, to group build output.
65+
OUT_DIR=$(GN_OUT_DIR)/example
66+
67+
# The GN build places all libraries at the top level of the output directory.
68+
FLUTTER_EMBEDDER_LIB=$(GN_OUT_DIR)/lib$(FLUTTER_EMBEDDER_LIB_NAME).so
69+
FLUTTER_ENGINE_LIB=$(GN_OUT_DIR)/lib$(FLUTTER_ENGINE_LIB_NAME).so
70+
PLUGIN_LIBS=$(foreach plugin,$(PLUGIN_NAMES)\
71+
,$(GN_OUT_DIR)/lib$(PLUGIN_LIB_NAME_PREFIX)$(plugin).so)
72+
73+
# The GN build places all published headers in a top-level include/.
74+
INCLUDE_DIRS=$(GN_OUT_DIR)/include
75+
76+
# Override LIBRARY_DIRS since it's used for controlling the external build.
77+
LIBRARY_DIRS=$(GN_OUT_DIR)
78+
79+
# Additional tools
80+
GN_WRAPPER=$(TOOLS_DIR)/gn_dart
81+
NINJA_BIN=ninja
82+
endif
83+
6184
# Build settings
6285
CXX=g++ -std=c++14
6386
CXXFLAGS=-Wall -Werror $(shell pkg-config --cflags jsoncpp)
@@ -85,6 +108,12 @@ $(BIN_OUT): $(SOURCES) $(ALL_LIBS_OUT)
85108
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(SOURCES) $(LDFLAGS) -o $@
86109

87110
# Depedency directories are used as phony targets to invoke their builds.
111+
ifdef USE_GN
112+
.PHONY: $(LIBRARY_DIRS)
113+
$(LIBRARY_DIRS):
114+
$(GN_WRAPPER) gen $(GN_OUT_DIR)
115+
$(NINJA_BIN) -C $(GN_OUT_DIR) $(FLUTTER_EMBEDDER_LIB_NAME) $(PLUGIN_NAMES)
116+
else
88117
.PHONY: $(LIBRARY_DIRS)
89118
$(LIBRARY_DIRS):
90119
$(MAKE) -C $@ $(MAKECMDGOALS)
@@ -93,6 +122,7 @@ $(LIBRARY_DIRS):
93122
# in parallel in the event that someone supplies the -j flag to `make`.
94123
# TODO: Fix this in the plugin builds so that it's not necessary at this layer.
95124
$(PLUGIN_DIRS): $(FLUTTER_EMBEDDER_LIB_DIR)
125+
endif
96126

97127
# Require that all the library builds run for anything depending on the
98128
# libraries, but use order-only so that the phony build targets don't trigger

library/BUILD.gn

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("//build/flutter.gni")
16+
import("//build/packaging.gni")
17+
import("//library/engine.gni")
18+
19+
published_shared_library("flutter_embedder") {
20+
if (is_linux) {
21+
sources = [
22+
"linux/src/internal/engine_method_result.cc",
23+
"linux/src/internal/engine_method_result.h",
24+
"linux/src/internal/json_message_codec.cc",
25+
"linux/src/internal/json_message_codec.h",
26+
"linux/src/internal/keyboard_hook_handler.h",
27+
"linux/src/internal/plugin_handler.cc",
28+
"linux/src/internal/plugin_handler.h",
29+
"linux/src/internal/text_input_model.cc",
30+
"linux/src/internal/text_input_model.h",
31+
"linux/src/internal/text_input_plugin.cc",
32+
"linux/src/internal/text_input_plugin.h",
33+
"linux/src/embedder.cc",
34+
"linux/src/json_method_call.cc",
35+
"linux/src/json_method_codec.cc",
36+
"linux/src/json_plugin.cc",
37+
"linux/src/method_call.cc",
38+
"linux/src/method_channel.cc",
39+
"linux/src/method_codec.cc",
40+
"linux/src/method_result.cc",
41+
"linux/src/plugin.cc",
42+
]
43+
public = [
44+
"linux/include/flutter_desktop_embedding/binary_messenger.h",
45+
"linux/include/flutter_desktop_embedding/embedder.h",
46+
"linux/include/flutter_desktop_embedding/json_method_call.h",
47+
"linux/include/flutter_desktop_embedding/json_method_codec.h",
48+
"linux/include/flutter_desktop_embedding/json_plugin.h",
49+
"linux/include/flutter_desktop_embedding/method_call.h",
50+
"linux/include/flutter_desktop_embedding/method_channel.h",
51+
"linux/include/flutter_desktop_embedding/method_codec.h",
52+
"linux/include/flutter_desktop_embedding/method_result.h",
53+
"linux/include/flutter_desktop_embedding/plugin.h",
54+
]
55+
}
56+
57+
deps = [
58+
":fetch_flutter_engine",
59+
]
60+
61+
if (is_linux) {
62+
public_header_subdir = "flutter_desktop_embedding"
63+
64+
deps += [
65+
"//library/linux:publish_flutter_engine",
66+
]
67+
68+
libs = [
69+
"glfw",
70+
"GL",
71+
]
72+
73+
configs += [
74+
"//build/linux/config:epoxy",
75+
"//build/linux/config:gtk3",
76+
"//build/linux/config:jsoncpp",
77+
"//build/linux/config:x11",
78+
]
79+
80+
public_configs = [
81+
"//library/linux:relative_public_headers",
82+
]
83+
}
84+
}
85+
86+
action("fetch_flutter_engine") {
87+
script = "//tools/dart_tools/bin/update_flutter_engine.dart"
88+
inputs = [ "$flutter_tree_path/bin/internal/engine.version" ]
89+
outputs = engine_files
90+
args = [
91+
"--flutter_root=$flutter_tree_path",
92+
rebase_path(engine_download_dir, root_build_dir),
93+
]
94+
}

0 commit comments

Comments
 (0)