SYCL rules for Bazel
This repository contains Starlark implementation of SYCL rules in Bazel.
These rules provide some macros and rules that make it easier to build SYCL with Bazel.
Add the following to your WORKSPACE file and replace the placeholders with actual values.
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "rules_sycl",
sha256 = "{sha256_to_replace}",
strip_prefix = "rules_sycl-{git_commit_hash}",
urls = ["https://github.com/loseall/rules_sycl/archive/{git_commit_hash}.tar.gz"],
)
load("@rules_sycl//sycl:repositories.bzl", "rules_sycl_dependencies", "rules_sycl_toolchains")
rules_sycl_dependencies()
rules_sycl_toolchains(register_toolchains = True)NOTE: rules_sycl_toolchains implicitly calls to register_detected_sycl_toolchains, and the use of
register_detected_sycl_toolchains depends on the environment variable CMPLR_ROOT. You must also ensure the
host compiler is available. On Windows, this means that you will also need to set the environment variable
BAZEL_VC properly (mostly not needed if you installed Visual Studio in default location).
detect_sycl_toolkit determains how the toolchains are detected.
Add the following to your MODULE.bazel file and replace the placeholders with actual values.
bazel_dep(name = "rules_sycl", version = "0.0.0")
# pick a specific version (this is optional an can be skipped)
archive_override(
module_name = "rules_sycl",
integrity = "{SRI value}", # see https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity
url = "https://github.com/loseall/rules_sycl/archive/{git_commit_hash}.tar.gz",
strip_prefix = "rules_sycl-{git_commit_hash}",
)
sycl = use_extension("@rules_sycl//sycl:extensions.bzl", "toolchain")
sycl.toolkit(
name = "sycl",
toolkit_path = "",
)
use_repo(sycl, "sycl")sycl_library: Can be used to compile and create static library for SYCL kernel code. The resulting targets can be consumed by C/C++ Rules.sycl_binary/sycl_test: Can be used to compile and create executable or shared library for SYCL kernel code.icx_cc_library: Can be used to compile and create static library for DPC++ code (without SYCL runtime involved). The resulting targets can be consumed by C/C++ Rules.icx_cc_binary/icx_cc_test: Can be used to compile and create executable or shared library for DPC++ code (without SYCL runtime involved).
Some flags are defined in sycl/BUILD.bazel. To use them, for example:
# not implemented yet!
bazel build --@rules_sycl//sycl:archs=rpl-p
In .bazelrc file, you can define a shortcut alias for the flag, for example:
# Convenient flag shortcuts.
build --flag_alias=sycl_archs=@rules_sycl//sycl:archs
and then you can use it as following:
bazel build --sycl_archs=rpl-p
Checkout the examples to see if it fits your needs.
See tests for basic usage.