1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 template("python_binary_module") {
6 # Only available on linux for now.
8 assert(defined(invoker.sources))
9 assert(defined(invoker.python_base_module))
11 cython_root = "//third_party/cython"
12 cython_script = "$cython_root/src/cython.py"
13 cython_output = "${target_out_dir}/${target_name}.cc"
15 generator_target_name = target_name + "_cython_compiler"
16 shared_library_name = target_name + "_shared_library"
17 config_name = target_name + "_python_config"
20 shared_library_prefix = "lib"
21 shared_library_suffix = ".so"
22 python_module_suffix = ".so"
26 ":$generator_target_name",
27 ":$shared_library_name",
31 action(generator_target_name) {
32 visibility = target_visibility
33 script = cython_script
34 sources = invoker.sources
35 outputs = [ cython_output ]
38 "-I", rebase_path("//", root_build_dir),
39 "-o", rebase_path(cython_output, root_build_dir),
40 ] + rebase_path(sources, root_build_dir)
44 visibility = target_visibility
45 python_flags = "//third_party/cython/python_flags.py"
46 include_dirs = exec_script(python_flags,
47 [ "--gn", "--includes" ],
49 libs = exec_script(python_flags,
50 [ "--gn", "--libraries" ],
52 lib_dirs = exec_script(python_flags,
53 [ "--gn", "--library_dirs" ],
56 # Generated code includes static utility functions that often go unused.
58 "-Wno-unused-function",
63 shared_library(shared_library_name) {
64 visibility = target_visibility
66 ":$generator_target_name",
68 if (defined(invoker.deps)) {
71 if (defined(invoker.datadeps)) {
72 datadeps = invoker.datadeps
74 sources = [ cython_output ]
75 if (defined(invoker.additional_sources)) {
76 sources += invoker.additional_sources
78 configs += [ ":$config_name" ]
79 if (defined(invoker.configs)) {
80 configs += invoker.configs
85 python_base_module = invoker.python_base_module
87 "$root_out_dir/${shared_library_prefix}${shared_library_name}${shared_library_suffix}"
90 "$root_out_dir/python/$python_base_module/${target_name}${python_module_suffix}"
93 ":$shared_library_name"