Blink roll 25b6bd3a7a131ffe68d809546ad1a20707915cdc:3a503f41ae42e5b79cfcd2ff10e65afde...
[chromium-blink-merge.git] / third_party / cython / rules.gni
blobefd9ca3e5eb1d7f3d32cf15b6a908a19f7ecd75e
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.
7   assert(is_linux)
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"
19   if (is_linux) {
20     shared_library_prefix = "lib"
21     shared_library_suffix = ".so"
22     python_module_suffix = ".so"
23   }
25   target_visibility = [
26     ":$generator_target_name",
27     ":$shared_library_name",
28     ":$target_name",
29   ]
31   action(generator_target_name) {
32     visibility = target_visibility
33     script = cython_script
34     sources = invoker.sources
35     outputs = [ cython_output ]
36     args = [
37       "--cplus",
38       "-I", rebase_path("//", root_build_dir),
39       "-o", rebase_path(cython_output, root_build_dir),
40     ] + rebase_path(sources, root_build_dir)
41   }
43   config(config_name) {
44     visibility = target_visibility
45     python_flags = "//third_party/cython/python_flags.py"
46     include_dirs = exec_script(python_flags,
47                                [ "--gn", "--includes" ],
48                                "list lines")
49     libs = exec_script(python_flags,
50                        [ "--gn", "--libraries" ],
51                        "list lines")
52     lib_dirs = exec_script(python_flags,
53                            [ "--gn", "--library_dirs" ],
54                            "list lines")
55     if (!is_win) {
56       # Generated code includes static utility functions that often go unused.
57       cflags = [
58         "-Wno-unused-function",
59       ]
60     }
61   }
63   shared_library(shared_library_name) {
64     visibility = target_visibility
65     deps = [
66       ":$generator_target_name",
67     ]
68     if (defined(invoker.deps)) {
69       deps += invoker.deps
70     }
71     if (defined(invoker.datadeps)) {
72       datadeps = invoker.datadeps
73     }
74     sources = [ cython_output ]
75     if (defined(invoker.additional_sources)) {
76       sources += invoker.additional_sources
77     }
78     configs += [ ":$config_name" ]
79     if (defined(invoker.configs)) {
80       configs += invoker.configs
81     }
82   }
84   copy(target_name) {
85     python_base_module = invoker.python_base_module
86     sources = [
87       "$root_out_dir/${shared_library_prefix}${shared_library_name}${shared_library_suffix}"
88     ]
89     outputs = [
90       "$root_out_dir/python/$python_base_module/${target_name}${python_module_suffix}"
91     ]
92     deps = [
93       ":$shared_library_name"
94     ]
95   }