opencc-sys 0.4.3+1.3.1

OpenCC bindings for Rust
Documentation
"""Bazel build rules for the OpenCC Node.js native addon (opencc.node)."""

load("@rules_cc//cc:defs.bzl", "cc_binary")

package(default_visibility = ["//visibility:public"])

# The shared library that becomes opencc.node.
# cc_binary with linkshared=True on Linux produces "libopencc_clib.so";
# on macOS it produces "libopencc_clib.dylib". We rename via genrule below.
#
# node-gyp and Bazel both compile the same binding source. node-gyp lists the
# OpenCC and marisa sources directly, while Bazel links against //src:opencc.
cc_binary(
    name = "opencc_clib",
    srcs = ["opencc.cc"],
    copts = select({
        "@platforms//os:windows": ["/std:c++20"],
        "//conditions:default": ["-std=c++20"],
    }),
    defines = [
        'VERSION=\\"1.3.1\\"',
        "NAPI_DISABLE_CPP_EXCEPTIONS",
        "Opencc_BUILT_AS_STATIC",
    ],
    includes = [".", "src"],
    linkopts = select({
        "@platforms//os:macos": ["-undefined", "dynamic_lookup", "-Wl,-S", "-Wl,-no_uuid"],
        "@platforms//os:linux": ["-Wl,-s", "-Wl,--build-id=sha1"],
        "//conditions:default": ["-Wl,-s"],
    }),
    linkshared = True,
    deps = [
        "@node_addon_api//:node_addon_api",
        "@node_headers//:node_headers",
        "//src:opencc",
        # Explicit sub-library deps for headers not in //src:opencc's hdrs:
        "//src:config",       # Config.hpp
        "//src:converter",    # Converter.hpp, ConversionInspection.hpp
        "//src:dict_converter",  # DictConverter.hpp
        "//src:exception",    # Exception.hpp
    ],
)

# ----------------------------------------------------------------
# Rename the platform-specific shared library to "opencc.node"
# ----------------------------------------------------------------
genrule(
    name = "opencc_node",
    srcs = [":opencc_clib"],
    outs = ["opencc.node"],
    cmd = "cp $(location :opencc_clib) $@",
)

genrule(
    name = "opencc_node_windows_zig",
    srcs = [
        "opencc.cc",
        "//deps/marisa-0.3.1:all_files",
        "//deps/rapidjson-1.1.0:all_files",
        "//src:all_files",
        "@node_addon_api//:all_files",
        "@node_headers//:all_files",
    ],
    outs = ["windows-x64/opencc.node"],
    cmd = (
        "bash $(location //scripts:build_node_windows_zig) " +
        "$@ " +
        "$(location @node_headers//:node_api_header) " +
        "$(location @node_addon_api//:napi_header) " +
        "$(location @node_win_x64_lib//file)"
    ),
    tools = [
        "//scripts:build_node_windows_zig",
        "@node_addon_api//:all_files",
        "@node_addon_api//:napi_header",
        "@node_headers//:all_files",
        "@node_headers//:node_api_header",
        "@node_win_x64_lib//file",
    ],
)