forked from LlsDimple/fidl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBUILD.gn
123 lines (108 loc) · 2.9 KB
/
BUILD.gn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# Copyright 2016 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
group("compiler") {
testonly = true
deps = [
":fidl",
":fidl-c",
":fidl-go",
":fidl-rust",
]
}
# Template for building Go binaries. Doesn't have all the features ever yet.
# Arguments:
# package: (required) the package to pass to "go build"
# gopath: (optional) the GOPATH variable to set
# output: (optional) the file to generate
template("go_binary") {
# TODO(ianloic): make this general and reusable and move it under //build
assert(defined(invoker.package), "package not defined for $target_name")
if (defined(invoker.gopath)) {
gopath = invoker.gopath
} else {
gopath = [ "//go" ]
}
gopath_str = ""
target_sources = []
foreach(path, rebase_path(gopath)) {
if (gopath_str != "") {
gopath_str += ":"
}
gopath_str += path
# TODO(ianloic): work out how to use go list to list the sources the target actually uses.
target_sources += exec_script("/usr/bin/find",
[
path,
"-type",
"f",
"-name",
"*.go",
"-print",
],
"list lines")
}
target_deps = [ ]
if (defined(invoker.deps)) {
target_deps += invoker.deps
}
go_binary = "//buildtools/go"
assert(host_os == "mac" || host_os == "linux")
if (host_os == "mac") {
goroot = rebase_path("//buildtools/mac/go")
} else {
goroot = rebase_path("//buildtools/linux64/go")
}
if (defined(invoker.output)) {
output_path = "${root_out_dir}/${invoker.output}"
} else {
output_path = "${root_out_dir}/${target_name}"
}
action(target_name) {
script = "/usr/bin/env"
# TODO(ianloic): support cross-compilation
# TODO(ianloic): use 'go install' instead of 'go build' to avoid recompiling more than is needed.
args = [
"GOPATH=${gopath_str}",
"GOROOT=${goroot}",
rebase_path(go_binary),
"build",
"-o",
rebase_path(output_path),
invoker.package,
]
sources = target_sources
outputs = [
output_path,
]
deps = target_deps
}
}
# Build the fidl compiler
go_binary("fidl") {
gopath = [
"//lib/fidl/go",
]
package = "fidl/compiler/cmd/fidl"
}
# Build the C generator
go_binary("fidl-c") {
gopath = [
"//lib/fidl/go",
]
package = "fidl/compiler/generators/c"
}
# Build the Go generator
go_binary("fidl-go") {
gopath = [
"//lib/fidl/go",
]
package = "fidl/compiler/generators/go"
}
# Build the Rust generator
go_binary("fidl-rust") {
gopath = [
"//lib/fidl/go",
]
package = "fidl/compiler/generators/rust"
}