| # Copyright 2023 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| # Defines a python C extension shared library. |
| # |
| # This is not directly importable into a Python `.pyz`. |
| # This builds a .so file that can be loaded into python if its parent directory |
| # is included in the PYTHONPATH environment variable. |
| template("python_c_extension_shared_lib") { |
| assert(defined(invoker.sources), "sources is required") |
| assert(is_host, "python C extensions can only be built on host") |
| |
| shared_library(target_name) { |
| output_prefix_override = true |
| forward_variables_from(invoker, |
| [ |
| "assert_no_deps", |
| "public_configs", |
| "testonly", |
| "sources", |
| "deps", |
| "visibility", |
| ]) |
| if (defined(invoker.configs)) { |
| configs += invoker.configs |
| } |
| configs += [ "//build/config/python:python_c_extension_shared_lib_config" ] |
| |
| if (!defined(invoker.deps)) { |
| deps = [] |
| } |
| deps += [ "//build/config/python:generate_python_api_symbols" ] |
| |
| if (host_os == "mac") { |
| configs += [ "//build/config/mac:symbol_dynamic_lookup_undefined" ] |
| |
| # For mac the usual naming convention is to have .dylib as the extension. |
| # However, Python only expects C extensions to have a .so extension. |
| output_extension = "so" |
| } |
| } |
| } |