Skip to content

Initial Linux GN build #149

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 4 commits into from
Nov 27, 2018
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
out/
.DS_Store
1 change: 1 addition & 0 deletions .gn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
buildconfig = "//build/BUILDCONFIG.gn"
22 changes: 22 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

group("gn_all") {
deps = [
"//library:flutter_embedder",
"//plugins/color_panel:color_panel",
"//plugins/file_chooser:file_chooser",
"//plugins/menubar:menubar",
]
}
32 changes: 32 additions & 0 deletions build/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

config("defaults") {
cflags = [
"-std=c++14",
"-Wall",
"-Werror",
"-pthread",
]
include_dirs = [
"//"
]
}

config("shared_library_defaults") {
cflags = [
"-shared",
"-fPIC",
]
}
42 changes: 42 additions & 0 deletions build/BUILDCONFIG.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set_default_toolchain("//third_party/chromium/build/toolchain:gcc")

set_defaults("executable") {
configs = [ "//build:defaults" ]
}
set_defaults("static_library") {
configs = [ "//build:defaults" ]
}
set_defaults("shared_library") {
configs = [ "//build:defaults", "//build:shared_library_defaults" ]
}
set_defaults("published_shared_library") {
configs = [ "//build:defaults", "//build:shared_library_defaults" ]
}

if (host_os == "linux") {
is_linux = true
is_mac = false
is_win = false
} else if (host_os == "mac") {
is_linux = false
is_mac = true
is_win = false
} else if (host_os == "win") {
is_linux = false
is_mac = false
is_win = true
}
21 changes: 21 additions & 0 deletions build/flutter.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

declare_args() {
# The path to the Flutter tree to use for any Flutter operations or assets.
# If empty, assumes a directory called 'flutter' that is a sibling of this
# repository (like tools/flutter_location; this duplication avoids shelling
# out).
flutter_tree_path = rebase_path("../../flutter")
}
31 changes: 31 additions & 0 deletions build/linux/config/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//third_party/chromium/build/config/linux/pkg_config.gni")

pkg_config("gtk3") {
packages = [ "gtk+-3.0" ]
}

pkg_config("epoxy") {
packages = [ "epoxy" ]
}

pkg_config("x11") {
packages = [ "x11" ]
}

pkg_config("jsoncpp") {
packages = [ "jsoncpp" ]
}
60 changes: 60 additions & 0 deletions build/packaging.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Puts the public headers of the invoker in public_header_subdir
# under the top-level include/ directory in the build output.
#
# This is intended to make consuming public headers of all the libraries built
# by GN easy for outside build systems on Linux, by requiring only a single
# include directory.
if (is_linux) {
template("copy_includes") {
copy(target_name) {
assert(defined(invoker.sources),
"|sources| must be provided for copy_includes.")
forward_variables_from(invoker, [ "deps", "sources", "subdir" ])
output_dir = "$root_out_dir/include"
if (defined(subdir)) {
output_dir = "$output_dir/$subdir"
}
outputs = [ "$output_dir/{{source_file_part}}"]
}
}
}

# An abstraction for a shared library with associated headers that is intended
# to be consumed from the build output.
#
# On Linux, this performs a copy_includes in addition to building the library.
template("published_shared_library") {
template_target_name = target_name

if (is_linux) {
copy_includes("_publish_${template_target_name}_headers") {
sources = invoker.public
subdir = invoker.public_header_subdir
}

shared_library(template_target_name) {
forward_variables_from(invoker, "*")
assert(defined(public),
"|public| must be provided for published_shared_library.")

if (!defined(deps)) {
deps = []
}
deps += [ ":_publish_${template_target_name}_headers" ]
}
}
}
30 changes: 30 additions & 0 deletions example/linux/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,29 @@ 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=$(PROJECT_ROOT)/out
# Use GN's out dir even though this isn't a GN build, to group build output.
OUT_DIR=$(GN_OUT_DIR)/example

# 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=-Wall -Werror $(shell pkg-config --cflags jsoncpp)
Expand Down Expand Up @@ -85,6 +108,12 @@ $(BIN_OUT): $(SOURCES) $(ALL_LIBS_OUT)
$(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)
$(NINJA_BIN) -C $(GN_OUT_DIR) $(FLUTTER_EMBEDDER_LIB_NAME) $(PLUGIN_NAMES)
else
.PHONY: $(LIBRARY_DIRS)
$(LIBRARY_DIRS):
$(MAKE) -C $@ $(MAKECMDGOALS)
Expand All @@ -93,6 +122,7 @@ $(LIBRARY_DIRS):
# 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
Expand Down
94 changes: 94 additions & 0 deletions library/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build/flutter.gni")
import("//build/packaging.gni")
import("//library/engine.gni")

published_shared_library("flutter_embedder") {
if (is_linux) {
sources = [
"linux/src/internal/engine_method_result.cc",
"linux/src/internal/engine_method_result.h",
"linux/src/internal/json_message_codec.cc",
"linux/src/internal/json_message_codec.h",
"linux/src/internal/keyboard_hook_handler.h",
"linux/src/internal/plugin_handler.cc",
"linux/src/internal/plugin_handler.h",
"linux/src/internal/text_input_model.cc",
"linux/src/internal/text_input_model.h",
"linux/src/internal/text_input_plugin.cc",
"linux/src/internal/text_input_plugin.h",
"linux/src/embedder.cc",
"linux/src/json_method_call.cc",
"linux/src/json_method_codec.cc",
"linux/src/json_plugin.cc",
"linux/src/method_call.cc",
"linux/src/method_channel.cc",
"linux/src/method_codec.cc",
"linux/src/method_result.cc",
"linux/src/plugin.cc",
]
public = [
"linux/include/flutter_desktop_embedding/binary_messenger.h",
"linux/include/flutter_desktop_embedding/embedder.h",
"linux/include/flutter_desktop_embedding/json_method_call.h",
"linux/include/flutter_desktop_embedding/json_method_codec.h",
"linux/include/flutter_desktop_embedding/json_plugin.h",
"linux/include/flutter_desktop_embedding/method_call.h",
"linux/include/flutter_desktop_embedding/method_channel.h",
"linux/include/flutter_desktop_embedding/method_codec.h",
"linux/include/flutter_desktop_embedding/method_result.h",
"linux/include/flutter_desktop_embedding/plugin.h",
]
}

deps = [
":fetch_flutter_engine",
]

if (is_linux) {
public_header_subdir = "flutter_desktop_embedding"

deps += [
"//library/linux:publish_flutter_engine",
]

libs = [
"glfw",
"GL",
]

configs += [
"//build/linux/config:epoxy",
"//build/linux/config:gtk3",
"//build/linux/config:jsoncpp",
"//build/linux/config:x11",
]

public_configs = [
"//library/linux:relative_public_headers",
]
}
}

action("fetch_flutter_engine") {
script = "//tools/dart_tools/bin/update_flutter_engine.dart"
inputs = [ "$flutter_tree_path/bin/internal/engine.version" ]
outputs = engine_files
args = [
"--flutter_root=$flutter_tree_path",
rebase_path(engine_download_dir, root_build_dir),
]
}
Loading