Skip to content

Commit 8df1271

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

4 files changed

Lines changed: 140 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: 109 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",
@@ -257,6 +263,101 @@ py_package(
257263
deps = [":litert_lm"],
258264
)
259265

266+
genrule(
267+
name = "copy_prebuilt_litert_lm_so",
268+
srcs = select({
269+
"//build_config:linux_x86_64": ["//prebuilt/linux_x86_64:liblitert-lm.so"],
270+
"//build_config:linux_arm64": ["//prebuilt/linux_arm64:liblitert-lm.so"],
271+
"//conditions:default": [],
272+
}),
273+
outs = ["liblitert-lm.so"],
274+
cmd = """
275+
SRCS_ARRAY=($(SRCS))
276+
OUTS_ARRAY=($(OUTS))
277+
if [ $${#SRCS_ARRAY[@]} -gt 0 ]; then
278+
cp $${SRCS_ARRAY[0]} $${OUTS_ARRAY[0]}
279+
chmod +w $${OUTS_ARRAY[0]}
280+
patchelf --set-rpath '$$ORIGIN' $${OUTS_ARRAY[0]}
281+
else
282+
touch $${OUTS_ARRAY[0]}
283+
fi
284+
""",
285+
tags = ["manual"],
286+
)
287+
288+
copy_file(
289+
name = "copy_prebuilt_litert_lm_dylib",
290+
src = "//prebuilt/macos_arm64:liblitert-lm.dylib",
291+
out = "liblitert-lm.dylib",
292+
)
293+
294+
copy_file(
295+
name = "copy_prebuilt_litert_lm_dll",
296+
src = "//prebuilt/windows_x86_64:litert-lm.dll",
297+
out = "litert-lm.dll",
298+
)
299+
300+
copy_file(
301+
name = "copy_dxcompiler_dll",
302+
src = "@directx_shader_compiler//:dxcompiler",
303+
out = "dxcompiler.dll",
304+
)
305+
306+
copy_file(
307+
name = "copy_dxil_dll",
308+
src = "@directx_shader_compiler//:dxil",
309+
out = "dxil.dll",
310+
)
311+
312+
filegroup(
313+
name = "prebuilt_litert_lm_lib",
314+
srcs = select({
315+
":wheel_platform_macos_arm64": [":copy_prebuilt_litert_lm_dylib"],
316+
":wheel_platform_windows_x86_64": [
317+
":copy_prebuilt_litert_lm_dll",
318+
":copy_dxcompiler_dll",
319+
":copy_dxil_dll",
320+
],
321+
":wheel_platform_linux_x86_64": [":copy_prebuilt_litert_lm_so"],
322+
":wheel_platform_linux_arm64": [":copy_prebuilt_litert_lm_so"],
323+
"//conditions:default": [],
324+
}),
325+
)
326+
327+
filegroup(
328+
name = "default_libs",
329+
srcs = ["//python/litert_lm:litert-lm"] + select({
330+
"@platforms//os:macos": [":copy_prebuilt_libs_dylib"],
331+
"@platforms//os:windows": [
332+
":copy_dxcompiler_dll",
333+
":copy_dxil_dll",
334+
],
335+
"//conditions:default": [":copy_prebuilt_libs_so"],
336+
}),
337+
)
338+
339+
340+
# Use "wheel_platform" to allow cross-compliling the wheel package.
341+
config_setting(
342+
name = "wheel_platform_linux_x86_64",
343+
define_values = {"wheel_platform": "linux_x86_64"},
344+
)
345+
346+
config_setting(
347+
name = "wheel_platform_linux_arm64",
348+
define_values = {"wheel_platform": "linux_arm64"},
349+
)
350+
351+
config_setting(
352+
name = "wheel_platform_windows_x86_64",
353+
define_values = {"wheel_platform": "windows_x86_64"},
354+
)
355+
356+
config_setting(
357+
name = "wheel_platform_macos_arm64",
358+
define_values = {"wheel_platform": "macos_arm64"},
359+
)
360+
260361
# To build normal wheel:
261362
# $ bazel build -c opt //python/litert_lm:wheel
262363
#
@@ -274,10 +375,10 @@ py_wheel(
274375
"//conditions:default": "litert-lm-api",
275376
}),
276377
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",
378+
":wheel_platform_linux_x86_64": "manylinux_2_35_x86_64",
379+
":wheel_platform_linux_arm64": "manylinux_2_35_aarch64",
380+
":wheel_platform_macos_arm64": "macosx_12_0_arm64",
381+
":wheel_platform_windows_x86_64": "win_amd64",
281382
"//conditions:default": "any",
282383
}),
283384
python_tag = "py3",

runtime/components/BUILD

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ load(
2323
"export_lrt_runtime_only_script",
2424
)
2525

26+
LITERT_MIN_IOS_VERSION = "14.0"
27+
28+
LITERT_MIN_MACOS_VERSION = "10.15"
29+
2630
package(
2731
default_hdrs_check = "strict",
2832
default_visibility = [

0 commit comments

Comments
 (0)