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