Skip to content

Commit 13da9c5

Browse files
whhonecopybara-github
authored andcommitted
[litertlm] add Windows DXC to WORKSPACE and for Python GPU API
LiteRT-LM-PiperOrigin-RevId: 908294380
1 parent 012bda6 commit 13da9c5

3 files changed

Lines changed: 164 additions & 8 deletions

File tree

BUILD.directx_shader_compiler

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
filegroup(
4+
name = "dxcompiler",
5+
srcs = ["bin/x64/dxcompiler.dll"],
6+
)
7+
8+
filegroup(
9+
name = "dxil",
10+
srcs = ["bin/x64/dxil.dll"],
11+
)
12+
13+
filegroup(
14+
name = "dxc_dlls",
15+
srcs = [
16+
"bin/x64/dxcompiler.dll",
17+
"bin/x64/dxil.dll",
18+
],
19+
)

WORKSPACE

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,3 +496,11 @@ pip_parse(
496496
load("@custom_pip_deps//:requirements.bzl", install_custom_deps = "install_deps")
497497

498498
install_custom_deps()
499+
500+
# DirectX Shader Compiler DLLs for Windows
501+
http_archive(
502+
name = "directx_shader_compiler",
503+
build_file = "@//:BUILD.directx_shader_compiler",
504+
sha256 = "a1e89031421cf3c1fca6627766ab3020ca4f962ac7e2caa7fab2b33a8436151e",
505+
url = "https://github.com/microsoft/DirectXShaderCompiler/releases/download/v1.9.2602/dxc_2026_02_20.zip",
506+
)

python/litert_lm/BUILD

Lines changed: 137 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,19 @@ pytype_strict_library(
143143
],
144144
)
145145

146+
config_setting(
147+
name = "use_prebuilt_c_api",
148+
define_values = {
149+
"use_prebuilt_c_api": "true",
150+
},
151+
)
152+
146153
pytype_strict_library(
147154
name = "litert_lm",
148155
srcs = ["__init__.py"],
149-
data = ["//python/litert_lm:litert-lm"] + select({
150-
"@platforms//os:macos": [":copy_prebuilt_libs_dylib"],
151-
"@platforms//os:windows": [], # the cc_binary rule already properly provisions this DLL into the package directory on Windows.
152-
"//conditions:default": [":copy_prebuilt_libs_so"],
156+
data = select({
157+
":use_prebuilt_c_api": [":prebuilt_litert_lm_lib"],
158+
"//conditions:default": [":default_libs"],
153159
}),
154160
deps = [
155161
":_ffi",
@@ -249,6 +255,129 @@ genrule(
249255
tags = ["manual"],
250256
)
251257

258+
genrule(
259+
name = "copy_prebuilt_libs_dll",
260+
srcs = select({
261+
":wheel_platform_windows_x86_64": ["//prebuilt/windows_x86_64:" + lib + ".dll" for lib in _PREBUILT_LIBS],
262+
"//conditions:default": [],
263+
}),
264+
outs = [lib + ".dll" for lib in _PREBUILT_LIBS],
265+
cmd = """
266+
SRCS_ARRAY=($(SRCS))
267+
OUTS_ARRAY=($(OUTS))
268+
if [ $${#SRCS_ARRAY[@]} -gt 0 ]; then
269+
for i in $${!SRCS_ARRAY[@]}; do
270+
cp $${SRCS_ARRAY[$$i]} $${OUTS_ARRAY[$$i]}
271+
done
272+
else
273+
for out in $${OUTS_ARRAY[@]}; do
274+
touch $$out
275+
done
276+
fi
277+
""",
278+
tags = ["manual"],
279+
)
280+
281+
genrule(
282+
name = "copy_prebuilt_litert_lm_so",
283+
srcs = select({
284+
"//build_config:linux_x86_64": ["//prebuilt/linux_x86_64:liblitert-lm.so"],
285+
"//build_config:linux_arm64": ["//prebuilt/linux_arm64:liblitert-lm.so"],
286+
"//conditions:default": [],
287+
}),
288+
outs = ["liblitert-lm.so"],
289+
cmd = """
290+
SRCS_ARRAY=($(SRCS))
291+
OUTS_ARRAY=($(OUTS))
292+
if [ $${#SRCS_ARRAY[@]} -gt 0 ]; then
293+
cp $${SRCS_ARRAY[0]} $${OUTS_ARRAY[0]}
294+
chmod +w $${OUTS_ARRAY[0]}
295+
patchelf --set-rpath '$$ORIGIN' $${OUTS_ARRAY[0]}
296+
else
297+
touch $${OUTS_ARRAY[0]}
298+
fi
299+
""",
300+
tags = ["manual"],
301+
)
302+
303+
copy_file(
304+
name = "copy_prebuilt_litert_lm_dylib",
305+
src = "//prebuilt/macos_arm64:liblitert-lm.dylib",
306+
out = "liblitert-lm.dylib",
307+
tags = ["manual"],
308+
)
309+
310+
copy_file(
311+
name = "copy_prebuilt_litert_lm_dll",
312+
src = "//prebuilt/windows_x86_64:litert-lm.dll",
313+
out = "litert-lm.dll",
314+
tags = ["manual"],
315+
)
316+
317+
copy_file(
318+
name = "copy_dxcompiler_dll",
319+
src = "@directx_shader_compiler//:dxcompiler",
320+
out = "dxcompiler.dll",
321+
)
322+
323+
copy_file(
324+
name = "copy_dxil_dll",
325+
src = "@directx_shader_compiler//:dxil",
326+
out = "dxil.dll",
327+
)
328+
329+
filegroup(
330+
name = "prebuilt_litert_lm_lib",
331+
srcs = select({
332+
":wheel_platform_macos_arm64": [":copy_prebuilt_litert_lm_dylib"],
333+
":wheel_platform_windows_x86_64": [
334+
":copy_prebuilt_litert_lm_dll",
335+
":copy_dxcompiler_dll",
336+
":copy_dxil_dll",
337+
],
338+
":wheel_platform_linux_x86_64": [":copy_prebuilt_litert_lm_so"],
339+
":wheel_platform_linux_arm64": [":copy_prebuilt_litert_lm_so"],
340+
"//conditions:default": [],
341+
}),
342+
)
343+
344+
filegroup(
345+
name = "default_libs",
346+
srcs = ["//python/litert_lm:litert-lm"] + select({
347+
"@platforms//os:macos": [":copy_prebuilt_libs_dylib"],
348+
"@platforms//os:windows": [
349+
":copy_prebuilt_libs_dll",
350+
":copy_dxcompiler_dll",
351+
":copy_dxil_dll",
352+
],
353+
":wheel_platform_linux_x86_64": [":copy_prebuilt_libs_so"],
354+
":wheel_platform_linux_arm64": [":copy_prebuilt_libs_so"],
355+
"//conditions:default": [],
356+
}),
357+
)
358+
359+
360+
# Use "wheel_platform" to allow cross-compliling the wheel package.
361+
config_setting(
362+
name = "wheel_platform_linux_x86_64",
363+
define_values = {"wheel_platform": "linux_x86_64"},
364+
)
365+
366+
config_setting(
367+
name = "wheel_platform_linux_arm64",
368+
define_values = {"wheel_platform": "linux_arm64"},
369+
)
370+
371+
config_setting(
372+
name = "wheel_platform_windows_x86_64",
373+
define_values = {"wheel_platform": "windows_x86_64"},
374+
)
375+
376+
config_setting(
377+
name = "wheel_platform_macos_arm64",
378+
define_values = {"wheel_platform": "macos_arm64"},
379+
)
380+
252381
py_package(
253382
name = "package",
254383
# Explicitly specify packages to avoid including transitively linked shared
@@ -274,10 +403,10 @@ py_wheel(
274403
"//conditions:default": "litert-lm-api",
275404
}),
276405
platform = select({
277-
"//build_config:linux_x86_64": "manylinux_2_35_x86_64",
278-
"//build_config:linux_arm64": "manylinux_2_35_aarch64",
279-
"@platforms//os:macos": "macosx_12_0_arm64",
280-
"@platforms//os:windows": "win_amd64",
406+
":wheel_platform_linux_x86_64": "manylinux_2_35_x86_64",
407+
":wheel_platform_linux_arm64": "manylinux_2_35_aarch64",
408+
":wheel_platform_macos_arm64": "macosx_12_0_arm64",
409+
":wheel_platform_windows_x86_64": "win_amd64",
281410
"//conditions:default": "any",
282411
}),
283412
python_tag = "py3",

0 commit comments

Comments
 (0)