summaryrefslogtreecommitdiffstats
path: root/mojo/nacl/BUILD.gn
blob: 8399df46ee1f536b214661d4a3d9444a117175ce (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
# Copyright (c) 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# TODO(dpranke) - it's very dangerous to have files being built with one
# toolchain having as part of the include_dirs a path to another toolchain's
# gen/ directory; it would be easy to end up including files meant for a
# different toolchain. We should either change this code to generate the
# files in every toolchain, or check in the generated code. Currently
# the plan is to do the latter.

# All toolchains use the same generated code.
gen_dir = "$root_build_dir/gen/mojo/nacl"

config("mojo_nacl") {
  include_dirs = [ "$root_build_dir/gen" ]
}

# Only allow the generator to be run by one toolchain.
if (current_toolchain == default_toolchain) {
  # Generate the code to plumb the Mojo public API into the NaCl sandbox.
  action("mojo_nacl_codegen") {
    script = "generator/generate_nacl_bindings.py"
    args = [
      "-d",
      rebase_path(gen_dir, root_build_dir),
    ]
    inputs = [
      script,
      "generator/interface.py",
      "generator/interface_dsl.py",
      "generator/mojo_syscall.cc.tmpl",
      "generator/libmojo.cc.tmpl",
    ]
    outputs = [
      "$gen_dir/mojo_irt.c",
      "$gen_dir/mojo_irt.h",
      "$gen_dir/mojo_syscall.cc",
      "$gen_dir/libmojo.cc",
    ]
  }
}

# Trusted code
if (!is_nacl) {
  # A library for launching a NaCl sandbox connected to a Mojo embedder.
  static_library("monacl_sel") {
    sources = [
      "mojo_syscall_internal.h",
      "$gen_dir/mojo_syscall.cc",
      "monacl_sel_main.cc",
    ]

    deps = [
      # This target makes sure we have all the pre-processor defines needed to
      # use NaCl's headers.
      "//native_client/build/config/nacl:nacl_base",
      "//native_client/src/trusted/desc:nrd_xfer",
      "//native_client/src/trusted/service_runtime:sel_main_chrome",
      ":mojo_nacl_codegen($default_toolchain)",
    ]
    public_configs =
        [ "//third_party/mojo/src/mojo/public/build/config:mojo_sdk" ]
  }
}

# Untrusted code
if (is_nacl) {
  # Thunk mapping the Mojo public API onto NaCl syscalls.
  static_library("mojo") {
    sources = [
      "$gen_dir/libmojo.cc",
      "$gen_dir/mojo_irt.h",
    ]

    public_configs = [
      ":mojo_nacl",
      "//third_party/mojo/src/mojo/public/build/config:mojo_sdk",
    ]

    public_deps = [
      ":mojo_nacl_codegen($default_toolchain)",
    ]
  }

  source_set("irt_mojo_sources") {
    cflags_c = [ "-std=c99" ]
    sources = [
      "$gen_dir/mojo_irt.c",
      "$gen_dir/mojo_irt.h",
    ]

    public_configs = [
      ":mojo_nacl",
      "//third_party/mojo/src/mojo/public/build/config:mojo_sdk",
    ]

    public_deps = [
      "//native_client/build/config/nacl:nacl_base",
      "//native_client/src/untrusted/irt:irt_core_lib",
      "//native_client/src/untrusted/nacl:imc_syscalls",
      ":mojo_nacl_codegen($default_toolchain)",
    ]
  }
}