aboutsummaryrefslogtreecommitdiff
path: root/third_party/jni/BUILD.bazel
blob: 21f3fe1f52b2c30238539c7be65285c7ce155eff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
load("@rules_cc//cc:defs.bzl", "cc_import", "cc_library")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")

cc_library(
    name = "jni",
    hdrs = [":jni_headers"],
    visibility = ["//visibility:public"],
    deps = select({
        "@platforms//os:osx": [":libjvm_osx"],
        "//conditions:default": [":libjvm_linux"],
    }),
)

cc_library(
    name = "jni_headers_only",
    hdrs = [
        ":jni_headers",
    ],
    visibility = ["//visibility:public"],
)

genrule(
    name = "jni_md_header",
    srcs = select({
        "@platforms//os:osx": ["@bazel_tools//tools/jdk:jni_md_header-darwin"],
        "@platforms//os:windows": ["@bazel_tools//tools/jdk:jni_md_header-windows"],
        "//conditions:default": ["@bazel_tools//tools/jdk:jni_md_header-linux"],
    }),
    outs = ["jni_md.h"],
    cmd = "cp -f $< $@",
)

genrule(
    name = "jni_header",
    srcs = ["@bazel_tools//tools/jdk:jni_header"],
    outs = ["jni.h"],
    cmd = "cp -f $< $@",
)

filegroup(
    name = "jni_headers",
    srcs = [
        ":jni_header",
        ":jni_md_header",
    ],
)

bool_flag(
    name = "jdk_8",
    build_setting_default = False,
)

config_setting(
    name = "is_jdk_8",
    flag_values = {
        ":jdk_8": "true",
    },
)

cc_import(
    name = "libjvm_osx",
    interface_library = select({
        ":is_jdk_8": "@local_jdk//:jre/lib/server/libjvm.dylib",
        "//conditions:default": "@local_jdk//:lib/server/libjvm.dylib",
    }),
    system_provided = True,
    # Workaround for https://github.com/bazelbuild/bazel/issues/12745
    tags = ["manual"],
)

cc_import(
    name = "libjvm_linux",
    interface_library = select({
        ":is_jdk_8": "@local_jdk//:jre/lib/amd64/server/libjvm.so",
        "//conditions:default": "@local_jdk//:lib/server/libjvm.so",
    }),
    system_provided = True,
    # Workaround for https://github.com/bazelbuild/bazel/issues/12745
    tags = ["manual"],
)