Skip to content

Commit

Permalink
third_party: make mkl a constraint [DIP-196] (#103)
Browse files Browse the repository at this point in the history
We need to model mkl version of the build as a proper platform with a
toolchain -
See: https://bazel.build/extending/platforms for more details.

Not having this in place is what caused our multi-arch builds to be
built against
vanilla x86 without mkl
  • Loading branch information
jungleraptor authored Nov 8, 2023
1 parent 32d3699 commit cb82c79
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions cc/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def register_swift_cc_toolchains():
native.register_toolchains("@rules_swiftnav//cc/toolchains/llvm/x86_64-darwin:cc-toolchain-x86_64-darwin")
native.register_toolchains("@rules_swiftnav//cc/toolchains/llvm/aarch64-linux:cc-toolchain-aarch64-linux")
native.register_toolchains("@rules_swiftnav//cc/toolchains/llvm/x86_64-linux:cc-toolchain-x86_64-linux")
native.register_toolchains("@rules_swiftnav//cc/toolchains/llvm/x86_64-linux:cc-toolchain-intel-mkl")
native.register_toolchains("@rules_swiftnav//cc/toolchains/llvm/x86_64-aarch64-linux:cc-toolchain-aarch64-bullseye-graviton2")
native.register_toolchains("@rules_swiftnav//cc/toolchains/llvm/x86_64-aarch64-linux:cc-toolchain-aarch64-bullseye-graviton3")

Expand Down
16 changes: 16 additions & 0 deletions cc/toolchains/llvm/x86_64-linux/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,19 @@ toolchain(
toolchain = ":cc-clang-x86_64-linux",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)

toolchain(
name = "cc-toolchain-intel-mkl",
exec_compatible_with = [
"@platforms//cpu:x86_64",
"@platforms//os:linux",
],
target_compatible_with = [
"@platforms//cpu:x86_64",
"@platforms//os:linux",
"//third_party:intel_mkl",
],
target_settings = None,
toolchain = ":cc-clang-x86_64-linux",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)
9 changes: 9 additions & 0 deletions platforms/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ platform(
visibility = ["//visibility:public"],
)

platform(
name = "intel_mkl",
constraint_values = [
"@platforms//os:linux",
"//third_party:intel_mkl",
"@platforms//cpu:x86_64",
],
)

platform(
name = "x86_64_linux_musl",
constraint_values = [
Expand Down
8 changes: 8 additions & 0 deletions third_party/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@

load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")

constraint_setting(name = "intel")

constraint_value(
name = "intel_mkl",
constraint_setting = ":intel",
visibility = ["//visibility:public"],
)

bool_flag(
name = "enable_mkl",
build_setting_default = False,
Expand Down
2 changes: 2 additions & 0 deletions third_party/eigen.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ cc_library(
defines = [
"EIGEN_NO_DEBUG",
] + select({
"@rules_swiftnav//third_party:intel_mkl": ["EIGEN_USE_MKL_ALL"],
"@rules_swiftnav//third_party:_enable_mkl": ["EIGEN_USE_MKL_ALL"],
"//conditions:default": [],
}),
includes = ["."],
deps = select({
"@rules_swiftnav//third_party:intel_mkl": ["@mkl"],
"@rules_swiftnav//third_party:_enable_mkl": ["@mkl"],
"//conditions:default": [],
}),
Expand Down

0 comments on commit cb82c79

Please sign in to comment.