summaryrefslogtreecommitdiff
path: root/deno2/deno.gni
blob: 66deaa96cc5d3ad6d4042d5ddf30d958d888ef2c (plain)
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
template("run_node") {
  action(target_name) {
    forward_variables_from(invoker, "*")
    script = "js/run_node.py"
  }
}

# Template to generate different V8 snapshots based on different runtime flags.
# Can be invoked with run_mksnapshot(<name>). The target will resolve to
# run_mksnapshot_<name>. If <name> is "default", no file suffixes will be used.
# Otherwise files are suffixed, e.g. embedded_<name>.cc and
# snapshot_blob_<name>.bin.
#
# The template exposes the variables:
#   args: additional flags for mksnapshots
#   embedded_suffix: a camel case suffix for method names in the embedded
#       snapshot.
template("create_snapshot") {
  name = target_name
  suffix = "_$name"
  action("create_snapshot_" + name) {
    forward_variables_from(invoker,
                           [
                             "testonly",
                             "deps",
                           ])
    visibility = [ ":*" ]  # Only targets in this file can depend on this.
    deps += [ ":snapshot_creator" ]
    script = "v8/tools/run.py"
    data = []
    exe = rebase_path(get_label_info(":snapshot_creator", "root_out_dir") +
                      "/snapshot_creator")
    snapshot_out_cc = "$target_gen_dir/snapshot${suffix}.cc"
    sources = [
      invoker.js,
    ]
    outputs = [
      snapshot_out_cc,
    ]
    args = [
      exe,
      rebase_path(invoker.js, root_build_dir),
      rebase_path(snapshot_out_cc, root_build_dir),
    ]

    # To debug snapshotting problems:
    #  args += ["--trace-serializer"]
    data = [
      invoker.js,
    ]
  }
}

template("rust_crate") {
  action(target_name) {
    forward_variables_from(invoker,
                           [
                             "cfg",
                             "crate_type",
                             "source_root",
                             "deps",
                             "rust_deps",
                           ])
    sources = [
      source_root,
    ]
    outputs = []
    depfile = "$target_gen_dir/$target_name.d"
    script = "v8/tools/run.py"

    args = [
      "rustc",
      rebase_path(source_root, root_build_dir),
      "--crate-name=$target_name",
      "--crate-type=$crate_type",
      "--emit=dep-info=" + rebase_path(depfile, root_build_dir),
    ]

    # We only use staticlib for the special "empty" lib.
    if (crate_type == "staticlib") {
      staticlib = "$target_out_dir/$target_name.a"
      outputs += [ staticlib ]
      args += [ "--emit=link=" + rebase_path(staticlib, root_build_dir) ]
    }

    if (crate_type == "rlib" || crate_type == "bin") {
      obj = "$target_out_dir/$target_name.o"
      outputs += [ obj ]
      args += [ "--emit=obj=" + rebase_path(obj, root_build_dir) ]
    }

    if (crate_type == "rlib") {
      rlib = "$target_out_dir/$target_name.rlib"
      outputs += [ rlib ]
      args += [ "--emit=link=" + rebase_path(rlib, root_build_dir) ]
    }

    if (is_debug) {
      args += [ "-g" ]
    }

    if (is_official_build) {
      args += [ "-O" ]
    }

    if (defined(cfg)) {
      foreach(c, cfg) {
        args += [
          "--cfg",
          c,
        ]
      }
    }

    if (!defined(deps)) {
      deps = []
    }

    if (defined(rust_deps)) {
      deps += rust_deps
      foreach(dep_label, rust_deps) {
        dep_name = get_label_info(dep_label, "name")
        dep_dir = get_label_info(dep_label, "target_out_dir")
        dep_rlib = "$dep_dir/$dep_name.rlib"
        args += [
          "--extern",
          "$dep_name=" + rebase_path(dep_rlib, root_build_dir),
        ]
      }
    }
  }
}

template("rust_library") {
  rust_crate(target_name) {
    crate_type = "rlib"
    forward_variables_from(invoker, "*")
  }
}

template("rust_executable") {
  bin_target = target_name + "_bin"
  rust_crate(bin_target) {
    crate_type = "bin"
    forward_variables_from(invoker, "*")
  }

  # By compiling an empty file as crate-type=staticlib we get all the code
  # for the rust stdlib, which are not included in the object file outputs
  # of other libs.
  stdlib_target = target_name + "_stdlib"
  rust_crate(stdlib_target) {
    crate_type = "staticlib"
    source_root = "empty.rs"
  }

  executable(target_name) {
    forward_variables_from(invoker, "*")

    if (!defined(deps)) {
      deps = []
    }

    deps += [
      ":" + bin_target,
      ":" + stdlib_target,
    ]

    libs = get_target_outputs(":" + bin_target) +
           get_target_outputs(":" + stdlib_target)

    if (defined(rust_deps)) {
      deps += rust_deps
      foreach(dep_label, rust_deps) {
        dep_name = get_label_info(dep_label, "name")
        dep_dir = get_label_info(dep_label, "target_out_dir")
        dep_obj = "$dep_dir/$dep_name.o"
        libs += [ dep_obj ]
      }
    }

    if (current_os == "mac") {
      libs += [ "resolv" ]
    }
    if (current_os == "win") {
      libs += [ "userenv.lib" ]
    }
  }
}