aboutsummaryrefslogtreecommitdiff
path: root/third_party/libjpeg_turbo.BUILD
blob: 4621f862ea843ff0e2beb1657cf189a4afe269b3 (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
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("@bazel_skylib//rules:select_file.bzl", "select_file")

filegroup(
    name = "all_files",
    srcs = glob(["**"]),
)

filegroup(
    name = "java_files",
    srcs = glob(["java/org/libjpegturbo/turbojpeg/*.java"]),
)

cc_import(
    name = "libawt",
    hdrs = [
        "@local_jdk//:include/jawt.h",
    ],
    shared_library = "@local_jdk//:lib/libawt.so",
)

cmake(
    name = "libjpeg_turbo",
    cache_entries = {
        "CMAKE_BUILD_TYPE": "Release",
        "CMAKE_C_COMPILER": "clang",
        "CMAKE_C_FLAGS": "-fsanitize=address,fuzzer-no-link",
        "CMAKE_SHARED_LINKER_FLAGS": "-fsanitize=address,fuzzer-no-link",
        "WITH_JAVA": "1",
    },
    lib_source = ":all_files",
    out_shared_libs = [
        "libjpeg.so",
        "libturbojpeg.so",
    ],
    deps = [
        ":libawt",
        "@fmeum_rules_jni//jni",
    ],
)

select_file(
    name = "libturbojpeg_so",
    srcs = ":libjpeg_turbo",
    subpath = "lib/libturbojpeg.so",
)

copy_file(
    name = "turbojpeg_native",
    src = ":libturbojpeg_so",
    out = "libturbojpeg.so",
    visibility = ["//visibility:public"],
)

genrule(
    name = "generate_jni_loader",
    outs = ["TJLoader.java"],
    cmd = "echo 'package org.libjpegturbo.turbojpeg; final class TJLoader { static void load() { System.loadLibrary(\"turbojpeg\"); }}' > $@",
)

java_library(
    name = "turbojpeg_java",
    srcs = [
        ":generate_jni_loader",
        ":java_files",
    ],
    visibility = ["//visibility:public"],
)