0001-Introduce-a-simple-native-Bazel-build.patch 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. From 04fb28b5673d29a8c38519845c87f4c00c76e9cf Mon Sep 17 00:00:00 2001
  2. From: Chandler Carruth <chandlerc@gmail.com>
  3. Date: Sat, 13 Jan 2024 02:15:19 -0800
  4. Subject: [PATCH] Introduce a simple native Bazel build.
  5. ---
  6. BUILD.bazel | 84 +++++++++++++++++++++++++++++++++++++++++++++++++
  7. MODULE.bazel | 10 ++++++
  8. WORKSPACE.bazel | 5 +++
  9. 3 files changed, 99 insertions(+)
  10. create mode 100644 BUILD.bazel
  11. create mode 100644 MODULE.bazel
  12. create mode 100644 WORKSPACE.bazel
  13. diff --git a/BUILD.bazel b/BUILD.bazel
  14. new file mode 100644
  15. index 0000000..427c854
  16. --- /dev/null
  17. +++ b/BUILD.bazel
  18. @@ -0,0 +1,84 @@
  19. +# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  20. +# Exceptions. See /LICENSE for license information.
  21. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  22. +
  23. +load("@rules_cc//cc:defs.bzl", "cc_library")
  24. +
  25. +package(default_visibility = ["//visibility:public"])
  26. +
  27. +aarch64_srcs = [
  28. + "lib/pfmlib_arm_perf_event.c",
  29. + "lib/pfmlib_arm.c",
  30. + "lib/pfmlib_arm_armv8.c",
  31. + "lib/pfmlib_arm_armv9.c",
  32. + "lib/pfmlib_tx2_unc_perf_event.c",
  33. + "lib/pfmlib_kunpeng_unc_perf_event.c",
  34. + "lib/pfmlib_arm_priv.h",
  35. + "lib/events/arm_cortex_a57_events.h",
  36. + "lib/events/arm_cortex_a53_events.h",
  37. + "lib/events/arm_xgene_events.h",
  38. + "lib/events/arm_cavium_tx2_events.h",
  39. + "lib/events/arm_marvell_tx2_unc_events.h",
  40. + "lib/events/arm_fujitsu_a64fx_events.h",
  41. + "lib/events/arm_neoverse_n1_events.h",
  42. + "lib/events/arm_neoverse_n2_events.h",
  43. + "lib/events/arm_neoverse_v1_events.h",
  44. + "lib/events/arm_neoverse_v2_events.h",
  45. + "lib/events/arm_hisilicon_kunpeng_events.h",
  46. + "lib/events/arm_hisilicon_kunpeng_unc_events.h",
  47. +]
  48. +
  49. +x86_64_srcs = [
  50. + "lib/pfmlib_amd64_priv.h",
  51. +] + glob(
  52. + [
  53. + "lib/pfmlib_amd64*.c",
  54. + "lib/pfmlib_intel*.c",
  55. + "lib/pfmlib_intel*_priv.h",
  56. + "lib/events/amd64_events_*.h",
  57. + "lib/events/intel_*_events.h",
  58. + ],
  59. + exclude = [
  60. + # 32-bit CPUs
  61. + "lib/pfmlib_intel_coreduo.c",
  62. + "lib/pfmlib_intel_p6.c",
  63. + ],
  64. +)
  65. +
  66. +cc_library(
  67. + name = "libpfm",
  68. + srcs = [
  69. + "lib/events/perf_events.h",
  70. + "lib/pfmlib_common.c",
  71. + "lib/pfmlib_perf_event.c",
  72. + "lib/pfmlib_perf_event_pmu.c",
  73. + "lib/pfmlib_perf_event_priv.h",
  74. + "lib/pfmlib_perf_event_raw.c",
  75. + "lib/pfmlib_priv.h",
  76. + ] + select({
  77. + "@platforms//cpu:aarch64": aarch64_srcs,
  78. + "@platforms//cpu:x86_64": x86_64_srcs,
  79. + }),
  80. + hdrs = glob(["include/perfmon/*.h"]),
  81. + copts = [
  82. + "-DHAS_OPENAT",
  83. + "-D_REENTRANT",
  84. + "-I.",
  85. + "-fvisibility=hidden",
  86. + ] + select({
  87. + "@platforms//cpu:x86_64": [
  88. + "-DCONFIG_PFMLIB_ARCH_X86",
  89. + "-DCONFIG_PFMLIB_ARCH_X86_64",
  90. + ],
  91. + "//conditions:default": [],
  92. + }),
  93. + strip_include_prefix = "include",
  94. + target_compatible_with = select({
  95. + # This library only makes sense on Linux, and we only include support
  96. + # for building on AArch64 and x86-64. Other CPUs can be added to this
  97. + # list if build support is added for them.
  98. + "@platforms//cpu:aarch64": ["@platforms//os:linux"],
  99. + "@platforms//cpu:x86_64": ["@platforms//os:linux"],
  100. + "//conditions:default": ["@platforms//:incompatible"],
  101. + }),
  102. +)
  103. diff --git a/MODULE.bazel b/MODULE.bazel
  104. new file mode 100644
  105. index 0000000..c901cbe
  106. --- /dev/null
  107. +++ b/MODULE.bazel
  108. @@ -0,0 +1,10 @@
  109. +# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  110. +# Exceptions. See /LICENSE for license information.
  111. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  112. +
  113. +"""Bazel modules."""
  114. +
  115. +module(name = "libpfm")
  116. +
  117. +bazel_dep(name = "rules_cc", version = "0.0.9")
  118. +bazel_dep(name = "platforms", version = "0.0.8")
  119. diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel
  120. new file mode 100644
  121. index 0000000..9aad57c
  122. --- /dev/null
  123. +++ b/WORKSPACE.bazel
  124. @@ -0,0 +1,5 @@
  125. +# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  126. +# Exceptions. See /LICENSE for license information.
  127. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  128. +
  129. +# See `MODULE.bazel` for details.
  130. --
  131. 2.43.0