BUILD.bazel 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License in the LICENSE file at the
  6. # root of this repository, or online at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. """
  16. Rules for executing pre-compiled binaries.
  17. This should only be used for non-essential tools like linters! Anything is used
  18. for building or running code should be included via a Bazel toolchain.
  19. """
  20. load("@bazel_skylib//rules:native_binary.bzl", "native_binary")
  21. native_binary(
  22. name = "buildifier",
  23. src = select(
  24. {
  25. "@//misc/bazel/platforms:macos_x86_64": "@buildifier-darwin-amd64//file",
  26. "@//misc/bazel/platforms:macos_arm": "@buildifier-darwin-arm64//file",
  27. "@//misc/bazel/platforms:linux_x86_64": "@buildifier-linux-amd64//file",
  28. "@//misc/bazel/platforms:linux_arm": "@buildifier-linux-arm64//file",
  29. },
  30. no_match_error = "`buildifier` is not supported on the current platform.",
  31. ),
  32. )
  33. # Note: We don't use `cargo` for building code, but some tools require it for generating metadata
  34. # for crates in our repo.
  35. native_binary(
  36. name = "cargo",
  37. src = select(
  38. {
  39. "@//misc/bazel/platforms:macos_x86_64": "@rust_macos_x86_64__x86_64-apple-darwin__stable_tools//:cargo",
  40. "@//misc/bazel/platforms:macos_arm": "@rust_macos_aarch64__aarch64-apple-darwin__stable_tools//:cargo",
  41. "@//misc/bazel/platforms:linux_x86_64": "@rust_linux_x86_64__x86_64-unknown-linux-gnu__stable_tools//:cargo",
  42. "@//misc/bazel/platforms:linux_arm": "@rust_linux_aarch64__aarch64-unknown-linux-gnu__stable_tools//:cargo",
  43. },
  44. no_match_error = "`cargo` is not supported on the current platform.",
  45. ),
  46. )
  47. # Convience wrapper around `cargo-gazelle` that specifies our formatter.
  48. sh_binary(
  49. name = "cargo-gazelle",
  50. srcs = ["@//misc/bazel/cargo-gazelle:main"],
  51. data = [
  52. "@//misc/bazel/tools:buildifier",
  53. "@//misc/bazel/tools:cargo",
  54. ],
  55. env = {
  56. "FORMATTER": "$(location @//misc/bazel/tools:buildifier)",
  57. "CARGO_BINARY": "$(location @//misc/bazel/tools:cargo)",
  58. },
  59. )
  60. # We alias some tools from the Clang toolchain for easy consumption from other
  61. # parts of our build system, e.g. `mzbuild.py`.
  62. #
  63. # To see all of the available tools, run `bazel cquery @llvm_toolchain_llvm//:bin --output=files`
  64. #
  65. # Note: In a _perfect_ Bazel world, we would have some rule that invokes these
  66. # tools and removes the need for the wrapper, but this is an incremental step.
  67. alias(
  68. name = "llvm-dwarfdump",
  69. actual = "@llvm_toolchain_llvm//:bin/llvm-dwarfdump",
  70. )
  71. alias(
  72. name = "dwarfdump",
  73. actual = ":llvm-dwarfdump",
  74. )
  75. alias(
  76. name = "llvm-objcopy",
  77. actual = "@llvm_toolchain_llvm//:bin/llvm-objcopy",
  78. )
  79. alias(
  80. name = "objcopy",
  81. actual = ":llvm-objcopy",
  82. )
  83. alias(
  84. name = "llvm-objdump",
  85. actual = "@llvm_toolchain_llvm//:bin/llvm-objdump",
  86. )
  87. alias(
  88. name = "objdump",
  89. actual = ":llvm-objdump",
  90. )
  91. alias(
  92. name = "llvm-profdata",
  93. actual = "@llvm_toolchain_llvm//:bin/llvm-profdata",
  94. )
  95. alias(
  96. name = "profdata",
  97. actual = ":llvm-profdata",
  98. )
  99. alias(
  100. name = "llvm-strip",
  101. actual = "@llvm_toolchain_llvm//:bin/llvm-strip",
  102. )
  103. alias(
  104. name = "strip",
  105. actual = ":llvm-strip",
  106. )