xref: /aosp_15_r20/external/skia/tools/skslc/BUILD.bazel (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1load("//bazel:skia_rules.bzl", "skia_cc_binary", "skia_cc_library", "skia_filegroup")
2load(":compile_sksl.bzl", "compile_sksl")
3
4package(
5    default_applicable_licenses = ["//:license"],
6)
7
8licenses(["notice"])
9
10skia_cc_binary(
11    name = "skslc",
12    srcs = [
13        "Main.cpp",
14    ],
15    deps = [
16        ":process_worklist",
17        "//:core",
18        "//src/sksl/codegen:glsl",
19        "//src/sksl/codegen:gpu",
20        "//src/sksl/codegen:hlsl",
21        "//src/sksl/codegen:metal",
22        "//src/sksl/codegen:spirv",
23        "//src/sksl/codegen:spirv_validator",
24        "//src/sksl/codegen:wgsl",
25        "//src/sksl/codegen:wgsl_validator",
26        "@spirv_tools",
27    ],
28)
29
30skia_cc_library(
31    name = "process_worklist",
32    srcs = ["ProcessWorklist.cpp"],
33    hdrs = ["ProcessWorklist.h"],
34    visibility = ["//tools/sksl-minify:__pkg__"],
35    deps = ["//:core"],
36)
37
38skia_filegroup(
39    name = "glsl_tests_with_settings",
40    srcs = [
41        "//resources/sksl:sksl_glsl_settings_tests_sources",
42        "//resources/sksl:sksl_glsl_tests_sources",
43    ],
44)
45
46# Invoke these using:
47#     bazel run //tools/skslc:compile_glsl_tests --config=compile_sksl
48compile_sksl(
49    name = "glsl_tests",
50    inputs = ":glsl_tests_with_settings",
51    lang = "glsl",
52)
53
54compile_sksl(
55    name = "glsl_nosettings_tests",
56    inputs = "//resources/sksl:sksl_glsl_settings_tests_sources",
57    lang = "glsl",
58    settings = "nosettings",
59)
60
61compile_sksl(
62    name = "metal_tests",
63    inputs = "//resources/sksl:sksl_metal_tests_sources",
64    lang = "metal",
65)
66
67compile_sksl(
68    name = "skrp_tests",
69    inputs = "//resources/sksl:sksl_skrp_tests_sources",
70    lang = "skrp",
71)
72
73compile_sksl(
74    name = "stage_tests",
75    inputs = "//resources/sksl:sksl_stage_tests_sources",
76    lang = "stage",
77)
78
79compile_sksl(
80    name = "spirv_tests",
81    inputs = "//resources/sksl:sksl_spirv_tests_sources",
82    lang = "spirv",
83)
84
85compile_sksl(
86    name = "hlsl_tests",
87    inputs = "//resources/sksl:sksl_hlsl_tests_sources",
88    lang = "hlsl",
89)
90
91compile_sksl(
92    name = "wgsl_tests",
93    inputs = "//resources/sksl:sksl_wgsl_tests_sources",
94    lang = "wgsl",
95)
96
97_SKSL_COMPILE_TESTS = """
98import glob
99import os
100import shutil
101import subprocess
102import sys
103
104# https://bazel.build/docs/user-manual#running-executables
105# Note: Bazel eats single quotes, so we must use double quotes.
106os.chdir(os.environ["BUILD_WORKSPACE_DIRECTORY"])
107
108# execpath returns the path to the given label relative to the Skia root.
109# This will be something like:
110#   bazel-out/k8-opt-exec-81C6BA4F/bin/tools/sksl-minify/sksl_minify
111# https://bazel.build/reference/be/make-variables#predefined_label_variables
112# We then find the absolute path because this is easier to debug and more
113# consistent if the script we are calling changes the working directory.
114sksl_compile_exe = os.path.abspath("$(execpath //tools/skslc:skslc)")
115compile_tests_script = os.path.abspath("$(execpath //gn:compile_sksl_tests)")
116
117# The last argument passed in is a file path from the root of the skia dir to a file
118# containing all the tests we want to process.
119input_file = os.path.abspath(sys.argv[-1])
120
121# skslc runs in standalone mode, which means it needs to read in several sksl files
122# instead of them being compiled in. These files need to be copied to the location
123# the executable is in, which is where it expects them.
124for sksl_file in glob.glob("src/sksl/*.sksl"):
125    shutil.copy(sksl_file, os.path.dirname(sksl_compile_exe))
126
127result = subprocess.run([
128    compile_tests_script,
129    sksl_compile_exe,
130] + sys.argv[1:-1] + [input_file], capture_output=True, encoding="utf-8")
131print(result.stdout)
132sys.exit(result.returncode)
133"""
134
135genrule(
136    name = "create_sksl_compile_tests_script",
137    # By putting skslc in srcs, this will be compiled for
138    # the target platform, not the exec platform. Importantly, this means that the
139    # Bazel config (e.g. no_config) will properly be applied to it. This shouldn't
140    # cause any problems unless the outputs of the compilation are
141    # used as the inputs to another step, because then cross-compiling
142    # would break (as we would be unable to, for example, run the
143    # "compiled for android skslc" on the exec machine that
144    # is running the Python script.
145    srcs = [":skslc"],
146    outs = ["sksl_compile_tests.py"],
147    cmd = "echo '%s' > $@" % _SKSL_COMPILE_TESTS,
148    tools = [
149        "//gn:compile_sksl_tests",
150    ],
151)
152