• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1load("@aspect_rules_js//npm:defs.bzl", "npm_package")
2load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
3
4filegroup(
5    name = "distribution",
6    srcs = [
7        "BUILD.bazel",
8        "compile_flat_file.sh",
9    ] + glob([
10        "*.ts",
11    ]),
12    visibility = ["//visibility:public"],
13)
14
15# Add an index to emulate the top-level package.json's "main" entry.
16genrule(
17    name = "generate_index.ts",
18    outs = ["index.ts"],
19    cmd = """echo "export * from './flatbuffers.js'" > $(OUTS)""",
20)
21
22ts_project(
23    name = "flatbuffers_ts",
24    srcs = [
25        "builder.ts",
26        "byte-buffer.ts",
27        "constants.ts",
28        "encoding.ts",
29        "flatbuffers.ts",
30        "types.ts",
31        "utils.ts",
32        ":index.ts",
33    ],
34    declaration = True,
35    tsconfig = {
36        "compilerOptions": {
37            "module": "commonjs",
38            "declaration": True,
39            "moduleResolution": "node",
40            "lib": [
41                "ES2015",
42                "ES2020.BigInt",
43                "DOM",
44            ],
45            "types": ["node"],
46            "strict": True,
47        },
48    },
49    visibility = ["//visibility:public"],
50    deps = [
51        # Because the main repository instantiates the @npm repository, we need
52        # to depend on the main repository's node import.
53        "@//:node_modules/@types/node",
54    ],
55)
56
57npm_package(
58    name = "flatbuffers",
59    srcs = [":flatbuffers_ts"],
60    include_external_repositories = ["*"],
61    package = "flatbuffers",
62    visibility = ["//visibility:public"],
63)
64
65sh_binary(
66    name = "compile_flat_file",
67    srcs = ["compile_flat_file.sh"],
68    data = [
69        "@com_github_google_flatbuffers//:flatc",
70        "@nodejs_linux_amd64//:node_bin",
71    ],
72    # We just depend directly on the linux amd64 nodejs binary, so only support
73    # running this script on amd64 for now.
74    target_compatible_with = [
75        "@platforms//cpu:x86_64",
76        "@platforms//os:linux",
77    ],
78    visibility = ["//visibility:public"],
79    deps = ["@bazel_tools//tools/bash/runfiles"],
80)
81