| # Copyright 2014 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. |
| |
| declare_args() { |
| # By default, there is no go build tool, because go builds are not supported. |
| go_build_tool = "" |
| } |
| |
| # Declare a go library. |
| # |
| # The target only writes a time stamp for input sources as the build is manages |
| # by the go tool. |
| # |
| # Variables: |
| # sources(required): list of .go files |
| # deps: dependencies for the go library |
| |
| template("go_library") { |
| action(target_name) { |
| sources = invoker.sources |
| script = "//mojo/go/stamp.py" |
| outputs = [ |
| "${target_out_dir}/${target_name}.script.stamp", |
| ] |
| if (defined(invoker.deps)) { |
| deps = invoker.deps |
| } |
| args = [ rebase_path(target_out_dir, root_build_dir) + |
| "/${target_name}.script.stamp" ] |
| } |
| } |
| |
| # Declare a go test binary target. |
| # |
| # The target generates a go test executable, linking against other C code, |
| # which is compiled into a static library and linked against Go. |
| # |
| # Only works on linux. |go_build_tool| must be set to the absolute path |
| # of the go build tool. |
| # |
| # Variables |
| # sources: list of .go files to compile |
| # inputs: list of files that are input dependencies. Use this to |
| # specify your imported .go files. These files will not be |
| # specified in the command line to go test but they will cause |
| # a re-compile if they are touched. (optional) |
| # static_library_sources: list of C sources needed for the static library |
| # (optional) |
| # deps: dependencies (optional) |
| |
| template("go_test_binary") { |
| # Only available on linux for now. |
| assert(is_linux) |
| assert(defined(invoker.sources)) |
| assert(go_build_tool != "") |
| |
| static_library_name = target_name + "_static_library" |
| |
| static_library(static_library_name) { |
| testonly = true |
| complete_static_lib = true |
| if (defined(invoker.static_library_sources)) { |
| sources = invoker.static_library_sources |
| } |
| if (defined(invoker.deps)) { |
| deps = invoker.deps |
| } |
| } |
| |
| action(target_name) { |
| testonly = true |
| deps = [ |
| ":$static_library_name", |
| ] |
| if (defined(invoker.deps)) { |
| deps += invoker.deps |
| } |
| script = "//mojo/go/go.py" |
| inputs = invoker.sources |
| if (defined(invoker.inputs)) { |
| inputs += invoker.inputs |
| } |
| outputs = [ |
| "${target_out_dir}/${target_name}", |
| ] |
| |
| # Since go test does not permit specifying an output directory or output |
| # binary name, we create a temporary build directory, and the python |
| # script will later identify the output, copy it to the target location, |
| # and clean up the temporary build directory. |
| build_dir = "${target_out_dir}/${target_name}_build" |
| args = [ |
| "--", |
| "${go_build_tool}", |
| rebase_path(build_dir, root_build_dir), |
| rebase_path(target_out_dir, root_build_dir) + "/${target_name}", |
| rebase_path("//", root_build_dir), |
| rebase_path(root_out_dir, root_build_dir), |
| "-I" + rebase_path("//"), |
| "-L" + rebase_path(target_out_dir) + " -l" + static_library_name + |
| " -lstdc++ -lpthread -lm -lglib-2.0 -lrt", |
| "test", |
| "-tags", |
| "include_mojo_cgo", |
| "-c", |
| ] + rebase_path(invoker.sources, build_dir) |
| } |
| } |
| |
| # Declare a go binary target. |
| # |
| # The target generates a go executable, optionally linking against C code, |
| # which is compiled into a static library and linked against Go. |
| # |
| # Only works on linux. |go_build_tool| must be set to the absolute path |
| # of the go build tool. |
| # |
| # Variables |
| # sources: list of top-level .go files to compile (required) |
| # inputs: list of files that are input dependencies. Use this to |
| # specify your imported .go files. These files will not be |
| # specified in the command line to go build but they will cause |
| # a re-compile if they are touched. (optional) |
| # static_library_sources: list of C sources needed for the static library |
| # (optional) |
| # deps: dependencies (optional) |
| # output_binary_name: name to use for the generated binary. |
| # If not provided the name ${target_name}_go will be used. |
| # Do not specify this to be equal to target_name or Ninja will |
| # give a warning about multiple targets generating the same output. |
| template("go_binary") { |
| assert(is_linux) |
| assert(defined(invoker.sources)) |
| assert(go_build_tool != "") |
| |
| static_library_name = target_name + "_static_library" |
| |
| static_library(static_library_name) { |
| complete_static_lib = true |
| |
| if (defined(invoker.static_library_sources)) { |
| sources = invoker.static_library_sources |
| } |
| if (defined(invoker.deps)) { |
| deps = invoker.deps |
| } |
| } |
| |
| go_binary_name = target_name + "_go_temp" |
| action(go_binary_name) { |
| deps = [ |
| ":${static_library_name}", |
| ] |
| if (defined(invoker.deps)) { |
| deps += invoker.deps |
| } |
| script = "//mojo/go/go.py" |
| inputs = invoker.sources |
| if (defined(invoker.inputs)) { |
| inputs += invoker.inputs |
| } |
| outputs = [ |
| "${target_out_dir}/${target_name}", |
| ] |
| |
| # Since go build does not permit specifying an output directory or output |
| # binary name, we create a temporary build directory, and the python |
| # script will later identify the output, copy it to the target location, |
| # and clean up the temporary build directory. |
| # TODO(rudominer) Update the version of go in the Mojo repo and then |
| # we will be able to use the -o flag instead. |
| build_dir = "${target_out_dir}/${target_name}_build" |
| args = [ |
| "--", |
| "${go_build_tool}", |
| rebase_path(build_dir, root_build_dir), |
| rebase_path(target_out_dir, root_build_dir) + "/${target_name}", |
| rebase_path("//", root_build_dir), |
| rebase_path(root_out_dir, root_build_dir), |
| "-I" + rebase_path("//"), |
| "-L" + rebase_path(target_out_dir) + " -l" + static_library_name + "", |
| "build", |
| ] |
| args += rebase_path(invoker.sources, build_dir) |
| } |
| |
| copy(target_name) { |
| output_binary_name = target_name + "_go" |
| if (defined(invoker.output_binary_name)) { |
| output_binary_name = invoker.output_binary_name |
| } |
| |
| deps = [ |
| ":${go_binary_name}", |
| ] |
| sources = [ |
| "${target_out_dir}/${go_binary_name}", |
| ] |
| outputs = [ |
| "${root_out_dir}/${output_binary_name}", |
| ] |
| } |
| } |
| |
| template("go_mojo_application") { |
| assert(is_android || is_linux || is_mac) |
| assert(defined(invoker.sources)) |
| assert(go_build_tool != "") |
| |
| static_library_name = target_name + "_static_library" |
| static_library(static_library_name) { |
| complete_static_lib = true |
| deps = [ |
| "//mojo/public/platform/native:system", |
| ] |
| } |
| |
| go_library_name = target_name + "_go" |
| action(go_library_name) { |
| deps = invoker.deps + [ |
| ":${static_library_name}", |
| "//mojo/go:application", |
| "//mojo/go:platform_cgo", |
| "//mojo/public/c/system", |
| ] |
| script = "//mojo/go/go.py" |
| inputs = invoker.sources |
| outputs = [ |
| "${target_out_dir}/${target_name}", |
| ] |
| |
| # Since go test does not permit specifying an output directory or output |
| # binary name, we create a temporary build directory, and the python |
| # script will later identify the output, copy it to the target location, |
| # and clean up the temporary build directory. |
| build_dir = "${target_out_dir}/${target_name}_build" |
| args = [] |
| if (is_android) { |
| args += [ "--target_os=android" ] |
| } else if (is_mac) { |
| args += [ "--target_os=mac" ] |
| } |
| args += [ |
| "--", |
| "${go_build_tool}", |
| rebase_path(build_dir, root_build_dir), |
| rebase_path(target_out_dir, root_build_dir) + "/${target_name}", |
| rebase_path("//", root_build_dir), |
| rebase_path(root_out_dir, root_build_dir), |
| "-I" + rebase_path("//"), |
| "-L" + rebase_path(target_out_dir) + " -l" + static_library_name + "", |
| "build", |
| "-tags", |
| "include_mojo_cgo", |
| ] |
| args += [ "-buildmode=c-shared" ] |
| args += rebase_path(invoker.sources, build_dir) |
| } |
| |
| copy(target_name) { |
| deps = [ |
| ":${go_library_name}", |
| ] |
| sources = [ |
| "${target_out_dir}/${go_library_name}", |
| ] |
| outputs = [ |
| "${root_out_dir}/${target_name}.mojo", |
| ] |
| } |
| } |