| 1 |
load("//bazel:skia_rules.bzl", "skia_cc_binary", "skia_cc_library", "skia_filegroup") |
| 2 |
load(":compile_sksl.bzl", "compile_sksl") |
| 3 |
|
| 4 |
package( |
| 5 |
default_applicable_licenses = ["//:license"], |
| 6 |
) |
| 7 |
|
| 8 |
licenses(["notice"]) |
| 9 |
|
| 10 |
skia_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 |
|
| 30 |
skia_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 |
|
| 38 |
skia_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 |
| 48 |
compile_sksl( |
| 49 |
name = "glsl_tests", |
| 50 |
inputs = ":glsl_tests_with_settings", |
| 51 |
lang = "glsl", |
| 52 |
) |
| 53 |
|
| 54 |
compile_sksl( |
| 55 |
name = "glsl_nosettings_tests", |
| 56 |
inputs = "//resources/sksl:sksl_glsl_settings_tests_sources", |
| 57 |
lang = "glsl", |
| 58 |
settings = "nosettings", |
| 59 |
) |
| 60 |
|
| 61 |
compile_sksl( |
| 62 |
name = "metal_tests", |
| 63 |
inputs = "//resources/sksl:sksl_metal_tests_sources", |
| 64 |
lang = "metal", |
| 65 |
) |
| 66 |
|
| 67 |
compile_sksl( |
| 68 |
name = "skrp_tests", |
| 69 |
inputs = "//resources/sksl:sksl_skrp_tests_sources", |
| 70 |
lang = "skrp", |
| 71 |
) |
| 72 |
|
| 73 |
compile_sksl( |
| 74 |
name = "stage_tests", |
| 75 |
inputs = "//resources/sksl:sksl_stage_tests_sources", |
| 76 |
lang = "stage", |
| 77 |
) |
| 78 |
|
| 79 |
compile_sksl( |
| 80 |
name = "spirv_tests", |
| 81 |
inputs = "//resources/sksl:sksl_spirv_tests_sources", |
| 82 |
lang = "spirv", |
| 83 |
) |
| 84 |
|
| 85 |
compile_sksl( |
| 86 |
name = "hlsl_tests", |
| 87 |
inputs = "//resources/sksl:sksl_hlsl_tests_sources", |
| 88 |
lang = "hlsl", |
| 89 |
) |
| 90 |
|
| 91 |
compile_sksl( |
| 92 |
name = "wgsl_tests", |
| 93 |
inputs = "//resources/sksl:sksl_wgsl_tests_sources", |
| 94 |
lang = "wgsl", |
| 95 |
) |
| 96 |
|
| 97 |
_SKSL_COMPILE_TESTS = """ |
| 98 |
import glob |
| 99 |
import os |
| 100 |
import shutil |
| 101 |
import subprocess |
| 102 |
import sys |
| 103 |
|
| 104 |
# https://bazel.build/docs/user-manual#running-executables |
| 105 |
# Note: Bazel eats single quotes, so we must use double quotes. |
| 106 |
os.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. |
| 114 |
sksl_compile_exe = os.path.abspath("$(execpath //tools/skslc:skslc)") |
| 115 |
compile_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. |
| 119 |
input_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. |
| 124 |
for sksl_file in glob.glob("src/sksl/*.sksl"): |
| 125 |
shutil.copy(sksl_file, os.path.dirname(sksl_compile_exe)) |
| 126 |
|
| 127 |
result = subprocess.run([ |
| 128 |
compile_tests_script, |
| 129 |
sksl_compile_exe, |
| 130 |
] + sys.argv[1:-1] + [input_file], capture_output=True, encoding="utf-8") |
| 131 |
print(result.stdout) |
| 132 |
sys.exit(result.returncode) |
| 133 |
""" |
| 134 |
|
| 135 |
genrule( |
| 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 |
) |