Skip to content

Commit ebe0af7

Browse files
CallumIddonstuartmorgan
authored andcommitted
[Windows] [GN] Windows GN Builds (#191)
Adds support for building the Windows embedding library using GN. Rewrites the batch scripts used by the Windows build as Dart scripts, so they can be used from GN. Part of #114
1 parent 62d3380 commit ebe0af7

26 files changed

+792
-264
lines changed

BUILD.gn

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@
1515
group("gn_all") {
1616
deps = [
1717
"//library:flutter_embedder",
18-
"//plugins/color_panel:color_panel",
19-
"//plugins/file_chooser:file_chooser",
20-
"//plugins/menubar:menubar",
2118
]
19+
if (is_linux) {
20+
deps += [
21+
"//plugins/color_panel:color_panel",
22+
"//plugins/file_chooser:file_chooser",
23+
"//plugins/menubar:menubar",
24+
]
25+
}
2226
}

analysis_options.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ linter:
2525
- avoid_null_checks_in_equality_operators
2626
- avoid_positional_boolean_parameters
2727
- avoid_private_typedef_functions
28-
- avoid_relative_lib_imports
28+
# TODO: Change relative imports for package imports
29+
# - avoid_relative_lib_imports
2930
# This puts an unnecessary burden on API clients.
3031
# - avoid_renaming_method_parameters
3132
- avoid_return_types_on_setters

build/BUILD.gn

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,31 @@
1313
# limitations under the License.
1414

1515
config("defaults") {
16-
cflags = [
17-
"-std=c++14",
18-
"-Wall",
19-
"-Werror",
20-
"-pthread",
21-
]
16+
if (is_linux) {
17+
cflags = [
18+
"-std=c++14",
19+
"-Wall",
20+
"-Werror",
21+
"-pthread",
22+
]
23+
}
24+
if (is_win) {
25+
cflags = [
26+
"/EHsc",
27+
"/W3",
28+
"/Od",
29+
]
30+
}
2231
include_dirs = [
23-
"//"
32+
"//",
2433
]
2534
}
2635

2736
config("shared_library_defaults") {
28-
cflags = [
29-
"-shared",
30-
"-fPIC",
31-
]
37+
if (is_linux) {
38+
cflags = [
39+
"-shared",
40+
"-fPIC",
41+
]
42+
}
3243
}

build/BUILDCONFIG.gn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
set_default_toolchain("//third_party/chromium/build/toolchain:gcc")
16-
1715
set_defaults("executable") {
1816
configs = [ "//build:defaults" ]
1917
}
@@ -28,6 +26,7 @@ set_defaults("published_shared_library") {
2826
}
2927

3028
if (host_os == "linux") {
29+
set_default_toolchain("//third_party/chromium/build/toolchain:gcc")
3130
is_linux = true
3231
is_mac = false
3332
is_win = false
@@ -36,6 +35,7 @@ if (host_os == "linux") {
3635
is_mac = true
3736
is_win = false
3837
} else if (host_os == "win") {
38+
set_default_toolchain("//build/win/toolchain:msvc")
3939
is_linux = false
4040
is_mac = false
4141
is_win = true

build/packaging.gni

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,29 @@
1616
# under the top-level include/ directory in the build output.
1717
#
1818
# 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}}"]
19+
# by GN easy for outside build systems, by requiring only a single include
20+
# directory.
21+
template("copy_includes") {
22+
copy(target_name) {
23+
assert(defined(invoker.sources),
24+
"|sources| must be provided for copy_includes.")
25+
forward_variables_from(invoker, [ "deps", "sources", "subdir" ])
26+
output_dir = "$root_out_dir/include"
27+
if (defined(subdir)) {
28+
output_dir = "$output_dir/$subdir"
3229
}
30+
outputs = [ "$output_dir/{{source_file_part}}"]
3331
}
3432
}
3533

3634
# An abstraction for a shared library with associated headers that is intended
3735
# to be consumed from the build output.
3836
#
39-
# On Linux, this performs a copy_includes in addition to building the library.
37+
# This performs a copy_includes in addition to building the library.
4038
template("published_shared_library") {
4139
template_target_name = target_name
4240

43-
if (is_linux) {
41+
if (is_linux || is_win) {
4442
copy_includes("_publish_${template_target_name}_headers") {
4543
sources = invoker.public
4644
subdir = invoker.public_header_subdir

build/win/config/BUILD.gn

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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("//library/windows/glfw.gni")
16+
import("//library/windows/jsoncpp.gni")
17+
18+
config("glfw3") {
19+
libs = [
20+
"$glfw_lib_name",
21+
"opengl32.lib",
22+
23+
"user32.lib",
24+
"gdi32.lib",
25+
"shell32.lib",
26+
]
27+
}
28+
29+
config("jsoncpp") {
30+
libs = [
31+
"$jsoncpp_lib_name",
32+
]
33+
}

build/win/toolchain/BUILD.gn

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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+
toolchain("msvc") {
16+
env_setup = "vcvars64.bat 1> nul &&"
17+
18+
tool("cc") {
19+
pdbfile = "{{target_out_dir}}/{{label_name}}_c.pdb"
20+
command = "$env_setup cl /nologo /showIncludes /MDd /FC {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} /c {{source}} /Fo{{output}} /Fd$pdbfile"
21+
depsformat = "msvc"
22+
description = "CC {{output}}"
23+
outputs = [
24+
"{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
25+
]
26+
}
27+
28+
tool("cxx") {
29+
pdbfile = "{{target_out_dir}}/{{label_name}}_c.pdb"
30+
command = "$env_setup cl /nologo /showIncludes /MDd /FC {{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} /c {{source}} /Fo{{output}} /Fd$pdbfile"
31+
depsformat = "msvc"
32+
description = "CXX {{output}}"
33+
outputs = [
34+
"{{source_out_dir}}/{{target_output_name}}.{{source_name_part}}.obj",
35+
]
36+
}
37+
38+
tool("alink") {
39+
rspfile = "{{output}}.rsp"
40+
command = "$env_setup lib /nologo /OUT:{{output}} @$rspfile"
41+
description = "AR {{target_output_name}}{{output_extension}}"
42+
rspfile_content = "{{inputs}}"
43+
outputs = [
44+
"{{target_out_dir}}/{{target_output_name}}{{output_extension}}",
45+
]
46+
default_output_extension = ".lib"
47+
}
48+
49+
tool("solink") {
50+
dllname = "{{target_output_name}}{{output_extension}}" # e.g. foo.dll
51+
dllfile = "{{output_dir}}/$dllname"
52+
libfile = dllname + ".lib" # e.g. foo.dll.lib
53+
pdbfile = dllname + ".pdb"
54+
rspfile = dllname + ".rsp"
55+
56+
command = "$env_setup link /nologo /DLL {{ldflags}} /IMPLIB:$libfile /OUT:$dllfile /DEBUG /PDB:$pdbfile @$rspfile"
57+
rspfile_content = "{{inputs}} {{solibs}} {{libs}}"
58+
59+
description = "SOLINK $dllfile"
60+
61+
# Use this for {{output_extension}} expansions unless a target manually
62+
# overrides it (in which case {{output_extension}} will be what the target
63+
# specifies).
64+
default_output_extension = ".dll"
65+
66+
# Use this for {{output_dir}} expansions unless a target manually overrides
67+
# it (in which case {{output_dir}} will be what the target specifies).
68+
default_output_dir = "{{root_out_dir}}"
69+
70+
lib_dir_switch = "/LIBPATH:"
71+
72+
outputs = [
73+
dllfile,
74+
libfile,
75+
pdbfile,
76+
]
77+
78+
link_output = dllfile
79+
depend_output = dllfile
80+
}
81+
82+
tool("link") {
83+
outfile = "{{target_output_name}}{{output_extension}}"
84+
rspfile = "$outfile.rsp"
85+
pdbfile = "$outfile.pdb"
86+
command = "$env_setup link {{ldflags}} /nologo /OUT:$outfile /PDB:$pdbfile @$rspfile"
87+
description = "LINK $outfile"
88+
default_output_dir = "{{root_out_dir}}"
89+
rspfile_content = "{{inputs}} {{libs}} {{solibs}}"
90+
lib_dir_switch = "/LIBPATH:"
91+
outputs = [
92+
outfile,
93+
]
94+
}
95+
96+
tool("stamp") {
97+
command = "cmd /c echo > {{output}}"
98+
description = "STAMP {{output}}"
99+
}
100+
101+
tool("copy") {
102+
command = "powershell -Command Copy-Item {{source}} {{output}}"
103+
description = "COPY {{source}} {{output}}"
104+
}
105+
}

example/windows/GLFW Example.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Dynamic Library|x64'">
5252
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\$(ProjectName)\</OutDir>
5353
<IntDir>$(SolutionDir)bin\intermediates\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
54-
<IncludePath>$(ProjectDir)..\..\library\windows\dependencies\;$(ProjectDir)..\..\;$(IncludePath);$(ProjectDir)..\..\library\windows\</IncludePath>
54+
<IncludePath>$(ProjectDir)..\..\library\windows\dependencies\;$(ProjectDir)..\..\library\include\;$(IncludePath)</IncludePath>
5555
<LibraryPath>$(ProjectDir)..\..\library\windows\dependencies\GLFW\;$(SolutionDir)bin\$(Platform)\$(Configuration)\GLFW Library\;$(LibraryPath)</LibraryPath>
5656
</PropertyGroup>
5757
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug Dynamic Library|x64'">

library/BUILD.gn

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,31 +69,61 @@ published_shared_library("flutter_embedder") {
6969
":fetch_flutter_engine",
7070
]
7171

72-
if (is_linux) {
73-
public_header_subdir = "flutter_desktop_embedding"
72+
public_header_subdir = "flutter_desktop_embedding"
7473

75-
deps += [
76-
"//library/linux:publish_flutter_engine",
77-
]
74+
public_configs = [
75+
":relative_public_headers",
76+
]
7877

78+
if (is_linux) {
7979
libs = [
8080
"glfw",
8181
"GL",
8282
]
8383

84+
deps += [
85+
"//library/linux:publish_flutter_engine",
86+
]
87+
8488
configs += [
8589
"//build/linux/config:epoxy",
8690
"//build/linux/config:gtk3",
8791
"//build/linux/config:jsoncpp",
8892
"//build/linux/config:x11",
8993
]
94+
}
95+
96+
if (is_win) {
97+
dll_exports = rebase_path("windows/exports.def")
98+
ldflags = [
99+
"/DEF:$dll_exports",
100+
]
101+
102+
deps += [
103+
"//library/windows:publish_flutter_engine",
104+
"//library/windows:fetch_glfw",
105+
"//library/windows:build_jsoncpp",
106+
]
90107

91-
public_configs = [
92-
"//library/linux:relative_public_headers",
108+
libs = [
109+
engine_files[2],
110+
]
111+
112+
public_configs += [
113+
"//library/windows:relative_glfw_dependencies",
114+
"//library/windows:relative_jsoncpp_dependencies",
93115
]
94116
}
95117
}
96118

119+
# Allows targets depending on this library to use library-style
120+
# inculdes for its header rather than project-relative.
121+
config("relative_public_headers") {
122+
include_dirs = [
123+
"include",
124+
]
125+
}
126+
97127
# Allows targets depending on the engine library to use library-style
98128
# inculdes for its header rather than project-relative.
99129
config("relative_engine_headers") {
@@ -110,9 +140,7 @@ action("fetch_flutter_engine") {
110140
"--flutter_root=$flutter_tree_path",
111141
rebase_path(engine_download_dir, root_build_dir),
112142
]
113-
if (is_linux) {
114-
public_configs = [
115-
":relative_engine_headers",
116-
]
117-
}
143+
public_configs = [
144+
":relative_engine_headers",
145+
]
118146
}

0 commit comments

Comments
 (0)