mesh-rb 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. checksums.yaml +7 -0
  2. data/.idea/.gitignore +8 -0
  3. data/.idea/mesh-rb.iml +16 -0
  4. data/.idea/misc.xml +4 -0
  5. data/.idea/modules.xml +8 -0
  6. data/.idea/vcs.xml +9 -0
  7. data/Gemfile +2 -0
  8. data/Gemfile.lock +17 -0
  9. data/Rakefile +16 -0
  10. data/bin/mesh +30 -0
  11. data/ext/mesh/extconf.rb +13 -0
  12. data/ext/mesh/mesh/.bazelrc +20 -0
  13. data/ext/mesh/mesh/.bazelversion +1 -0
  14. data/ext/mesh/mesh/.clang-format +15 -0
  15. data/ext/mesh/mesh/.dockerignore +5 -0
  16. data/ext/mesh/mesh/.editorconfig +16 -0
  17. data/ext/mesh/mesh/.gitattributes +4 -0
  18. data/ext/mesh/mesh/.github/workflows/main.yml +144 -0
  19. data/ext/mesh/mesh/.gitignore +51 -0
  20. data/ext/mesh/mesh/AUTHORS +5 -0
  21. data/ext/mesh/mesh/CMakeLists.txt +270 -0
  22. data/ext/mesh/mesh/CODE_OF_CONDUCT.md +77 -0
  23. data/ext/mesh/mesh/Dockerfile +30 -0
  24. data/ext/mesh/mesh/LICENSE +201 -0
  25. data/ext/mesh/mesh/Makefile +81 -0
  26. data/ext/mesh/mesh/README.md +97 -0
  27. data/ext/mesh/mesh/WORKSPACE +50 -0
  28. data/ext/mesh/mesh/bazel +350 -0
  29. data/ext/mesh/mesh/mesh-pldi19-powers.pdf +0 -0
  30. data/ext/mesh/mesh/src/BUILD +222 -0
  31. data/ext/mesh/mesh/src/CMakeLists.txt +85 -0
  32. data/ext/mesh/mesh/src/bitmap.h +590 -0
  33. data/ext/mesh/mesh/src/cheap_heap.h +170 -0
  34. data/ext/mesh/mesh/src/common.h +377 -0
  35. data/ext/mesh/mesh/src/copts.bzl +31 -0
  36. data/ext/mesh/mesh/src/d_assert.cc +75 -0
  37. data/ext/mesh/mesh/src/fixed_array.h +124 -0
  38. data/ext/mesh/mesh/src/global_heap.cc +547 -0
  39. data/ext/mesh/mesh/src/global_heap.h +569 -0
  40. data/ext/mesh/mesh/src/gnu_wrapper.cc +75 -0
  41. data/ext/mesh/mesh/src/internal.h +356 -0
  42. data/ext/mesh/mesh/src/libmesh.cc +239 -0
  43. data/ext/mesh/mesh/src/mac_wrapper.cc +528 -0
  44. data/ext/mesh/mesh/src/measure_rss.cc +44 -0
  45. data/ext/mesh/mesh/src/measure_rss.h +20 -0
  46. data/ext/mesh/mesh/src/meshable_arena.cc +776 -0
  47. data/ext/mesh/mesh/src/meshable_arena.h +309 -0
  48. data/ext/mesh/mesh/src/meshing.h +60 -0
  49. data/ext/mesh/mesh/src/mini_heap.h +532 -0
  50. data/ext/mesh/mesh/src/mmap_heap.h +104 -0
  51. data/ext/mesh/mesh/src/one_way_mmap_heap.h +77 -0
  52. data/ext/mesh/mesh/src/partitioned_heap.h +111 -0
  53. data/ext/mesh/mesh/src/plasma/mesh.h +33 -0
  54. data/ext/mesh/mesh/src/real.cc +52 -0
  55. data/ext/mesh/mesh/src/real.h +36 -0
  56. data/ext/mesh/mesh/src/rng/mwc.h +296 -0
  57. data/ext/mesh/mesh/src/rng/mwc64.h +58 -0
  58. data/ext/mesh/mesh/src/rpl_printf.c +1991 -0
  59. data/ext/mesh/mesh/src/runtime.cc +393 -0
  60. data/ext/mesh/mesh/src/runtime.h +114 -0
  61. data/ext/mesh/mesh/src/shuffle_vector.h +287 -0
  62. data/ext/mesh/mesh/src/size_classes.def +251 -0
  63. data/ext/mesh/mesh/src/static/if.h +36 -0
  64. data/ext/mesh/mesh/src/static/log.h +43 -0
  65. data/ext/mesh/mesh/src/testing/benchmark/local_refill.cc +103 -0
  66. data/ext/mesh/mesh/src/testing/big-alloc.c +28 -0
  67. data/ext/mesh/mesh/src/testing/fragmenter.cc +128 -0
  68. data/ext/mesh/mesh/src/testing/global-large-stress.cc +25 -0
  69. data/ext/mesh/mesh/src/testing/local-alloc.c +16 -0
  70. data/ext/mesh/mesh/src/testing/meshing_benchmark.cc +189 -0
  71. data/ext/mesh/mesh/src/testing/thread.cc +35 -0
  72. data/ext/mesh/mesh/src/testing/unit/alignment.cc +56 -0
  73. data/ext/mesh/mesh/src/testing/unit/bitmap_test.cc +274 -0
  74. data/ext/mesh/mesh/src/testing/unit/concurrent_mesh_test.cc +185 -0
  75. data/ext/mesh/mesh/src/testing/unit/mesh_test.cc +143 -0
  76. data/ext/mesh/mesh/src/testing/unit/rng_test.cc +22 -0
  77. data/ext/mesh/mesh/src/testing/unit/size_class_test.cc +66 -0
  78. data/ext/mesh/mesh/src/testing/unit/triple_mesh_test.cc +285 -0
  79. data/ext/mesh/mesh/src/testing/userfaultfd-kernel-copy.cc +164 -0
  80. data/ext/mesh/mesh/src/thread_local_heap.cc +163 -0
  81. data/ext/mesh/mesh/src/thread_local_heap.h +268 -0
  82. data/ext/mesh/mesh/src/wrapper.cc +433 -0
  83. data/ext/mesh/mesh/support/export_mesh.cmake +28 -0
  84. data/ext/mesh/mesh/support/gen-size-classes +57 -0
  85. data/ext/mesh/mesh/support/install_all_configs +33 -0
  86. data/ext/mesh/mesh/support/remove_export_mesh.cmake +48 -0
  87. data/ext/mesh/mesh/support/update-bazelisk +8 -0
  88. data/ext/mesh/mesh/theory/32m80.png +0 -0
  89. data/ext/mesh/mesh/theory/64m80ind.png +0 -0
  90. data/ext/mesh/mesh/theory/bound_comparison.py +67 -0
  91. data/ext/mesh/mesh/theory/bounds/impdeg+1 +135 -0
  92. data/ext/mesh/mesh/theory/choose.py +43 -0
  93. data/ext/mesh/mesh/theory/common.py +42 -0
  94. data/ext/mesh/mesh/theory/compute_exp_Y.py +134 -0
  95. data/ext/mesh/mesh/theory/createRandomString.py +69 -0
  96. data/ext/mesh/mesh/theory/deg_bound_check.py +100 -0
  97. data/ext/mesh/mesh/theory/degcheck.py +47 -0
  98. data/ext/mesh/mesh/theory/dumps/32,1,80,dumb.txt +81 -0
  99. data/ext/mesh/mesh/theory/dumps/32,2,80,dumb.txt +81 -0
  100. data/ext/mesh/mesh/theory/dumps/32,3,80,dumb.txt +81 -0
  101. data/ext/mesh/mesh/theory/dumps/32,4,80,dumb.txt +81 -0
  102. data/ext/mesh/mesh/theory/dumps/32,5,80,dumb.txt +81 -0
  103. data/ext/mesh/mesh/theory/dumps/32,6,80,dumb.txt +81 -0
  104. data/ext/mesh/mesh/theory/dumps/32,7,80,dumb.txt +81 -0
  105. data/ext/mesh/mesh/theory/dumps/32,8,80,dumb.txt +81 -0
  106. data/ext/mesh/mesh/theory/dumps/32,9,80,dumb.txt +81 -0
  107. data/ext/mesh/mesh/theory/experiment.py +303 -0
  108. data/ext/mesh/mesh/theory/experiment_raw_results/.gitignore +0 -0
  109. data/ext/mesh/mesh/theory/greedy_experiment.py +66 -0
  110. data/ext/mesh/mesh/theory/greedy_experiment_copy.py +46 -0
  111. data/ext/mesh/mesh/theory/greedy_experiment_q.py +75 -0
  112. data/ext/mesh/mesh/theory/makeGraph.py +64 -0
  113. data/ext/mesh/mesh/theory/manyreps.png +0 -0
  114. data/ext/mesh/mesh/theory/manystrings.png +0 -0
  115. data/ext/mesh/mesh/theory/match_vs_color_experiment.py +94 -0
  116. data/ext/mesh/mesh/theory/maxmatch_vs_E[Y].py +162 -0
  117. data/ext/mesh/mesh/theory/maxmatch_vs_greedymatch.py +96 -0
  118. data/ext/mesh/mesh/theory/maxvdeg+1imp++32,80.png +0 -0
  119. data/ext/mesh/mesh/theory/mesh_util.py +322 -0
  120. data/ext/mesh/mesh/theory/meshers.py +452 -0
  121. data/ext/mesh/mesh/theory/meshingBenchmark.py +96 -0
  122. data/ext/mesh/mesh/theory/occupancyComparison.py +133 -0
  123. data/ext/mesh/mesh/theory/randmatch_vs_greedymatch.py +97 -0
  124. data/ext/mesh/mesh/theory/randmatch_vs_greedymatch_q.py +103 -0
  125. data/ext/mesh/mesh/theory/randmatch_vs_greedymatch_time.py +117 -0
  126. data/ext/mesh/mesh/theory/read_mesh_dump.py +82 -0
  127. data/ext/mesh/mesh/theory/test.py +70 -0
  128. data/ext/mesh/mesh/tools/bazel +1 -0
  129. data/lib/mesh/version.rb +3 -0
  130. data/mesh.gemspec +14 -0
  131. metadata +172 -0
@@ -0,0 +1,50 @@
1
+ # Copyright 2020 The Mesh Authors. All rights reserved.
2
+ # Use of this source code is governed by the Apache License,
3
+ # Version 2.0, that can be found in the LICENSE file.
4
+
5
+ workspace(name = "org_libmesh")
6
+
7
+ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
8
+
9
+ commit = {
10
+ "rules_cc": "5cbd3dfbd1613f71ef29bbb7b10310b81e272975",
11
+ "googletest": "c6e309b268d4fb9138bed7d0f56b7709c29f102f",
12
+ "benchmark": "15e6dfd7182b74b4fb6860f52fe314d0654307fb",
13
+ "heap_layers": "08ca96cfe11b1dd1c504fb7be613ad00756d568f",
14
+ }
15
+
16
+ http_archive(
17
+ name = "rules_cc",
18
+ sha256 = "d6775fe03da086dfe47c668f54e77e220aa6e601a66a4517eaf19fa1d9fda309",
19
+ strip_prefix = "rules_cc-{}".format(commit["rules_cc"]),
20
+ urls = [
21
+ "https://github.com/bazelbuild/rules_cc/archive/{}.zip".format(commit["rules_cc"]),
22
+ ],
23
+ )
24
+
25
+ http_archive(
26
+ name = "com_google_googletest",
27
+ sha256 = "ac0b859e4c28af555657c7702523465756eb56f8606bf53e62fd934c86b5fa5f",
28
+ strip_prefix = "googletest-{}".format(commit["googletest"]),
29
+ urls = [
30
+ "https://github.com/google/googletest/archive/{}.zip".format(commit["googletest"]),
31
+ ],
32
+ )
33
+
34
+ http_archive(
35
+ name = "com_google_benchmark",
36
+ # sha256 = "",
37
+ strip_prefix = "benchmark-{}".format(commit["benchmark"]),
38
+ urls = [
39
+ "https://github.com/google/benchmark/archive/{}.zip".format(commit["benchmark"]),
40
+ ],
41
+ )
42
+
43
+ http_archive(
44
+ name = "org_heaplayers",
45
+ sha256 = "c8a9f7589e13112515ba1ac8647b4e80462f18a6773f7f5f132a7d7602fe2aec",
46
+ strip_prefix = "Heap-Layers-{}".format(commit["heap_layers"]),
47
+ urls = [
48
+ "https://github.com/emeryberger/Heap-Layers/archive/{}.zip".format(commit["heap_layers"]),
49
+ ],
50
+ )
@@ -0,0 +1,350 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Copyright 2018 Google Inc. All rights reserved.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+ """
17
+
18
+ from contextlib import closing
19
+ from distutils.version import LooseVersion
20
+ import json
21
+ import os
22
+ import os.path
23
+ import platform
24
+ import re
25
+ import shutil
26
+ import subprocess
27
+ import sys
28
+ import tempfile
29
+ import time
30
+
31
+ try:
32
+ from urllib.request import urlopen
33
+ except ImportError:
34
+ # Python 2.x compatibility hack.
35
+ from urllib2 import urlopen
36
+
37
+ ONE_HOUR = 1 * 60 * 60
38
+
39
+ LATEST_PATTERN = re.compile(r"latest(-(?P<offset>\d+))?$")
40
+
41
+ LAST_GREEN_COMMIT_BASE_PATH = (
42
+ "https://storage.googleapis.com/bazel-untrusted-builds/last_green_commit/"
43
+ )
44
+
45
+ LAST_GREEN_COMMIT_PATH_SUFFIXES = {
46
+ "last_green": "github.com/bazelbuild/bazel.git/bazel-bazel",
47
+ "last_downstream_green": "downstream_pipeline",
48
+ }
49
+
50
+ BAZEL_GCS_PATH_PATTERN = (
51
+ "https://storage.googleapis.com/bazel-builds/artifacts/{platform}/{commit}/bazel"
52
+ )
53
+
54
+ SUPPORTED_PLATFORMS = {"linux": "ubuntu1404", "windows": "windows", "darwin": "macos"}
55
+
56
+ TOOLS_BAZEL_PATH = "./tools/bazel"
57
+
58
+ BAZEL_REAL = "BAZEL_REAL"
59
+
60
+
61
+ def decide_which_bazel_version_to_use():
62
+ # Check in this order:
63
+ # - env var "USE_BAZEL_VERSION" is set to a specific version.
64
+ # - env var "USE_NIGHTLY_BAZEL" or "USE_BAZEL_NIGHTLY" is set -> latest
65
+ # nightly. (TODO)
66
+ # - env var "USE_CANARY_BAZEL" or "USE_BAZEL_CANARY" is set -> latest
67
+ # rc. (TODO)
68
+ # - the file workspace_root/tools/bazel exists -> that version. (TODO)
69
+ # - workspace_root/.bazelversion exists -> read contents, that version.
70
+ # - workspace_root/WORKSPACE contains a version -> that version. (TODO)
71
+ # - fallback: latest release
72
+ if "USE_BAZEL_VERSION" in os.environ:
73
+ return os.environ["USE_BAZEL_VERSION"]
74
+
75
+ workspace_root = find_workspace_root()
76
+ if workspace_root:
77
+ bazelversion_path = os.path.join(workspace_root, ".bazelversion")
78
+ if os.path.exists(bazelversion_path):
79
+ with open(bazelversion_path, "r") as f:
80
+ return f.read().strip()
81
+
82
+ return "latest"
83
+
84
+
85
+ def find_workspace_root(root=None):
86
+ if root is None:
87
+ root = os.getcwd()
88
+ if os.path.exists(os.path.join(root, "WORKSPACE")):
89
+ return root
90
+ new_root = os.path.dirname(root)
91
+ return find_workspace_root(new_root) if new_root != root else None
92
+
93
+
94
+ def resolve_version_label_to_number_or_commit(bazelisk_directory, version):
95
+ """Resolves the given label to a released version of Bazel or a commit.
96
+
97
+ Args:
98
+ bazelisk_directory: string; path to a directory that can store
99
+ temporary data for Bazelisk.
100
+ version: string; the version label that should be resolved.
101
+ Returns:
102
+ A (string, bool) tuple that consists of two parts:
103
+ 1. the resolved number of a Bazel release (candidate), or the commit
104
+ of an unreleased Bazel binary,
105
+ 2. An indicator for whether the returned version refers to a commit.
106
+ """
107
+ suffix = LAST_GREEN_COMMIT_PATH_SUFFIXES.get(version)
108
+ if suffix:
109
+ return get_last_green_commit(suffix), True
110
+
111
+ if "latest" in version:
112
+ match = LATEST_PATTERN.match(version)
113
+ if not match:
114
+ raise Exception(
115
+ 'Invalid version "{}". In addition to using a version '
116
+ 'number such as "0.20.0", you can use values such as '
117
+ '"latest" and "latest-N", with N being a non-negative '
118
+ "integer.".format(version)
119
+ )
120
+
121
+ history = get_version_history(bazelisk_directory)
122
+ offset = int(match.group("offset") or "0")
123
+ return resolve_latest_version(history, offset), False
124
+
125
+ return version, False
126
+
127
+
128
+ def get_last_green_commit(path_suffix):
129
+ return read_remote_text_file(LAST_GREEN_COMMIT_BASE_PATH + path_suffix).strip()
130
+
131
+
132
+ def get_releases_json(bazelisk_directory):
133
+ """Returns the most recent versions of Bazel, in descending order."""
134
+ releases = os.path.join(bazelisk_directory, "releases.json")
135
+
136
+ # Use a cached version if it's fresh enough.
137
+ if os.path.exists(releases):
138
+ if abs(time.time() - os.path.getmtime(releases)) < ONE_HOUR:
139
+ with open(releases, "rb") as f:
140
+ try:
141
+ return json.loads(f.read().decode("utf-8"))
142
+ except ValueError:
143
+ print("WARN: Could not parse cached releases.json.")
144
+ pass
145
+
146
+ with open(releases, "wb") as f:
147
+ body = read_remote_text_file("https://api.github.com/repos/bazelbuild/bazel/releases")
148
+ f.write(body.encode("utf-8"))
149
+ return json.loads(body)
150
+
151
+
152
+ def read_remote_text_file(url):
153
+ with closing(urlopen(url)) as res:
154
+ body = res.read()
155
+ try:
156
+ return body.decode(res.info().get_content_charset("iso-8859-1"))
157
+ except AttributeError:
158
+ # Python 2.x compatibility hack
159
+ return body.decode(res.info().getparam("charset") or "iso-8859-1")
160
+
161
+
162
+ def get_version_history(bazelisk_directory):
163
+ ordered = sorted(
164
+ (
165
+ LooseVersion(release["tag_name"])
166
+ for release in get_releases_json(bazelisk_directory)
167
+ if not release["prerelease"]
168
+ ),
169
+ reverse=True,
170
+ )
171
+ return [str(v) for v in ordered]
172
+
173
+
174
+ def resolve_latest_version(version_history, offset):
175
+ if offset >= len(version_history):
176
+ version = "latest-{}".format(offset) if offset else "latest"
177
+ raise Exception(
178
+ 'Cannot resolve version "{}": There are only {} Bazel '
179
+ "releases.".format(version, len(version_history))
180
+ )
181
+
182
+ # This only works since we store the history in descending order.
183
+ return version_history[offset]
184
+
185
+
186
+ def get_operating_system():
187
+ operating_system = platform.system().lower()
188
+ if operating_system not in ("linux", "darwin", "windows"):
189
+ raise Exception(
190
+ 'Unsupported operating system "{}". '
191
+ "Bazel currently only supports Linux, macOS and Windows.".format(operating_system)
192
+ )
193
+ return operating_system
194
+
195
+
196
+ def determine_bazel_filename(version):
197
+ machine = normalized_machine_arch_name()
198
+ if machine != "x86_64":
199
+ raise Exception(
200
+ 'Unsupported machine architecture "{}". Bazel currently only supports x86_64.'.format(
201
+ machine
202
+ )
203
+ )
204
+
205
+ operating_system = get_operating_system()
206
+
207
+ filename_ending = ".exe" if operating_system == "windows" else ""
208
+ return "bazel-{}-{}-{}{}".format(version, operating_system, machine, filename_ending)
209
+
210
+
211
+ def normalized_machine_arch_name():
212
+ machine = platform.machine().lower()
213
+ if machine == "amd64":
214
+ machine = "x86_64"
215
+ return machine
216
+
217
+
218
+ def determine_url(version, is_commit, bazel_filename):
219
+ if is_commit:
220
+ sys.stderr.write("Using unreleased version at commit {}\n".format(version))
221
+ # No need to validate the platform thanks to determine_bazel_filename().
222
+ return BAZEL_GCS_PATH_PATTERN.format(
223
+ platform=SUPPORTED_PLATFORMS[platform.system().lower()], commit=version
224
+ )
225
+
226
+ # Split version into base version and optional additional identifier.
227
+ # Example: '0.19.1' -> ('0.19.1', None), '0.20.0rc1' -> ('0.20.0', 'rc1')
228
+ (version, rc) = re.match(r"(\d*\.\d*(?:\.\d*)?)(rc\d+)?", version).groups()
229
+ return "https://releases.bazel.build/{}/{}/{}".format(
230
+ version, rc if rc else "release", bazel_filename
231
+ )
232
+
233
+
234
+ def download_bazel_into_directory(version, is_commit, directory):
235
+ bazel_filename = determine_bazel_filename(version)
236
+ url = determine_url(version, is_commit, bazel_filename)
237
+ destination_path = os.path.join(directory, bazel_filename)
238
+ if not os.path.exists(destination_path):
239
+ sys.stderr.write("Downloading {}...\n".format(url))
240
+ with tempfile.NamedTemporaryFile(prefix="bazelisk", dir=directory, delete=False) as t:
241
+ with closing(urlopen(url)) as response:
242
+ shutil.copyfileobj(response, t)
243
+ t.flush()
244
+ os.fsync(t.fileno())
245
+ os.rename(t.name, destination_path)
246
+ os.chmod(destination_path, 0o755)
247
+ return destination_path
248
+
249
+
250
+ def get_bazelisk_directory():
251
+ bazelisk_home = os.environ.get("BAZELISK_HOME")
252
+ if bazelisk_home is not None:
253
+ return bazelisk_home
254
+
255
+ operating_system = get_operating_system()
256
+
257
+ base_dir = None
258
+
259
+ if operating_system == "windows":
260
+ base_dir = os.environ.get("LocalAppData")
261
+ if base_dir is None:
262
+ raise Exception("%LocalAppData% is not defined")
263
+ elif operating_system == "darwin":
264
+ base_dir = os.environ.get("HOME")
265
+ if base_dir is None:
266
+ raise Exception("$HOME is not defined")
267
+ base_dir = os.path.join(base_dir, "Library/Caches")
268
+ elif operating_system == "linux":
269
+ base_dir = os.environ.get("XDG_CACHE_HOME")
270
+ if base_dir is None:
271
+ base_dir = os.environ.get("HOME")
272
+ if base_dir is None:
273
+ raise Exception("neither $XDG_CACHE_HOME nor $HOME are defined")
274
+ base_dir = os.path.join(base_dir, ".cache")
275
+ else:
276
+ raise Exception("Unsupported operating system '{}'".format(operating_system))
277
+
278
+ return os.path.join(base_dir, "bazelisk")
279
+
280
+
281
+ def maybe_makedirs(path):
282
+ """
283
+ Creates a directory and its parents if necessary.
284
+ """
285
+ try:
286
+ os.makedirs(path)
287
+ except OSError as e:
288
+ if not os.path.isdir(path):
289
+ raise e
290
+
291
+
292
+ def delegate_tools_bazel(bazel_path):
293
+ """Match Bazel's own delegation behavior in the builds distributed by most
294
+ package managers: use tools/bazel if it's present, executable, and not this
295
+ script.
296
+ """
297
+ root = find_workspace_root()
298
+ if root:
299
+ wrapper = os.path.join(root, TOOLS_BAZEL_PATH)
300
+ if os.path.exists(wrapper) and os.access(wrapper, os.X_OK):
301
+ try:
302
+ if not os.path.samefile(wrapper, __file__):
303
+ return wrapper
304
+ except AttributeError:
305
+ # Python 2 on Windows does not support os.path.samefile
306
+ if os.path.abspath(wrapper) != os.path.abspath(__file__):
307
+ return wrapper
308
+ return None
309
+
310
+
311
+ def execute_bazel(bazel_path, argv):
312
+ wrapper = delegate_tools_bazel(bazel_path)
313
+ if wrapper:
314
+ os.putenv(BAZEL_REAL, bazel_path)
315
+ bazel_path = wrapper
316
+
317
+ # We cannot use close_fds on Windows, so disable it there.
318
+ p = subprocess.Popen([bazel_path] + argv, close_fds=os.name != "nt")
319
+ while True:
320
+ try:
321
+ return p.wait()
322
+ except KeyboardInterrupt:
323
+ # Bazel will also get the signal and terminate.
324
+ # We should continue waiting until it does so.
325
+ pass
326
+
327
+
328
+ def get_bazel_path():
329
+ bazelisk_directory = get_bazelisk_directory()
330
+ maybe_makedirs(bazelisk_directory)
331
+
332
+ bazel_version = decide_which_bazel_version_to_use()
333
+ bazel_version, is_commit = resolve_version_label_to_number_or_commit(
334
+ bazelisk_directory, bazel_version
335
+ )
336
+
337
+ bazel_directory = os.path.join(bazelisk_directory, "bin")
338
+ maybe_makedirs(bazel_directory)
339
+ return download_bazel_into_directory(bazel_version, is_commit, bazel_directory)
340
+
341
+
342
+ def main(argv=None):
343
+ if argv is None:
344
+ argv = sys.argv
345
+
346
+ return execute_bazel(get_bazel_path(), argv[1:])
347
+
348
+
349
+ if __name__ == "__main__":
350
+ sys.exit(main())
@@ -0,0 +1,222 @@
1
+ # Copyright 2020 The Mesh Authors. All rights reserved.
2
+ # Use of this source code is governed by the Apache License,
3
+ # Version 2.0, that can be found in the LICENSE file.
4
+
5
+ load("//src:copts.bzl", "MESH_DEFAULT_COPTS")
6
+
7
+ package(default_visibility = ["//visibility:private"])
8
+
9
+ licenses(["notice"]) # Apache 2.0
10
+
11
+ # used in copts.bzl to set llvm/gcc-only flags
12
+ config_setting(
13
+ name = "llvm",
14
+ flag_values = {
15
+ "@bazel_tools//tools/cpp:compiler": "llvm",
16
+ },
17
+ visibility = ["//visibility:private"],
18
+ )
19
+
20
+ config_setting(
21
+ name = "disable_meshing",
22
+ values = {
23
+ "define": "disable_meshing=true",
24
+ },
25
+ visibility = ["//visibility:private"],
26
+ )
27
+
28
+ config_setting(
29
+ name = "disable_randomization",
30
+ values = {
31
+ "define": "disable_randomization=true",
32
+ },
33
+ visibility = ["//visibility:private"],
34
+ )
35
+
36
+ config_setting(
37
+ name = "shuffle_on_free",
38
+ values = {
39
+ "define": "shuffle_on_free=true",
40
+ },
41
+ visibility = ["//visibility:private"],
42
+ )
43
+
44
+ NO_BUILTIN_MALLOC = [
45
+ "-fno-builtin-malloc",
46
+ "-fno-builtin-free",
47
+ ]
48
+
49
+ COMMON_DEFINES = [] + select({
50
+ ":disable_meshing": ["MESHING_ENABLED=0"],
51
+ "//conditions:default": ["MESHING_ENABLED=1"],
52
+ }) + select({
53
+ ":disable_randomization": ["SHUFFLE_ON_INIT=0"],
54
+ "//conditions:default": ["SHUFFLE_ON_INIT=1"],
55
+ }) + select({
56
+ ":shuffle_on_free": ["SHUFFLE_ON_FREE=1"],
57
+ "//conditions:default": ["SHUFFLE_ON_FREE=0"],
58
+ }) + select({
59
+ "@bazel_tools//src/conditions:linux_x86_64": [
60
+ # "_FORTIFY_SOURCE=2", # TODO: only in release; but I think Bazel takes care of this?
61
+ "_DEFAULT_SOURCE",
62
+ "_BSD_SOURCE",
63
+ "_XOPEN_SOURCE=700",
64
+ ],
65
+ "//conditions:default": [],
66
+ })
67
+
68
+ COMMON_LINKOPTS = [
69
+ "-lm",
70
+ "-lpthread",
71
+ "-ldl",
72
+ ] + select({
73
+ "@bazel_tools//src/conditions:linux_x86_64": [
74
+ "-Wl,--no-as-needed",
75
+ "-Wl,--no-add-needed",
76
+ "-Wl,--sort-common",
77
+ "-Wl,--hash-style=both",
78
+ "-Wl,--no-undefined",
79
+ "-Wl,-Bsymbolic-functions",
80
+ "-Wl,-z,now,-z,relro",
81
+ "-Wl,--exclude-libs=libc++.a",
82
+ "-Wl,--exclude-libs=libc++abi.a",
83
+ "-Wl,--exclude-libs=libunwind.a",
84
+ ],
85
+ "//conditions:default": [],
86
+ })
87
+
88
+ cc_library(
89
+ name = "mesh-core",
90
+ srcs = [
91
+ "d_assert.cc",
92
+ "global_heap.cc",
93
+ "measure_rss.cc",
94
+ "meshable_arena.cc",
95
+ "real.cc",
96
+ "runtime.cc",
97
+ "thread_local_heap.cc",
98
+ ],
99
+ hdrs = glob([
100
+ "*.h",
101
+ "plasma/*.h",
102
+ "rng/*.h",
103
+ "gnu_wrapper.cc",
104
+ "mac_wrapper.cc",
105
+ "rpl_printf.c",
106
+ "static/*.h",
107
+ "size_classes.def",
108
+ ]),
109
+ copts = NO_BUILTIN_MALLOC + MESH_DEFAULT_COPTS,
110
+ defines = COMMON_DEFINES,
111
+ linkopts = COMMON_LINKOPTS,
112
+ linkstatic = True,
113
+ visibility = ["//visibility:private"],
114
+ deps = [
115
+ "@org_heaplayers",
116
+ ],
117
+ )
118
+
119
+ cc_library(
120
+ name = "mesh-lib",
121
+ srcs = [
122
+ "libmesh.cc",
123
+ ],
124
+ hdrs = glob([
125
+ "*.h",
126
+ "plasma/*.h",
127
+ "rng/*.h",
128
+ "gnu_wrapper.cc",
129
+ "mac_wrapper.cc",
130
+ "static/*.h",
131
+ "size_classes.def",
132
+ "wrapper.cc",
133
+ ]),
134
+ # TODO: config options here too
135
+ copts = NO_BUILTIN_MALLOC + MESH_DEFAULT_COPTS,
136
+ defines = COMMON_DEFINES,
137
+ linkopts = COMMON_LINKOPTS,
138
+ linkstatic = True,
139
+ visibility = ["//visibility:private"],
140
+ deps = [
141
+ "@org_heaplayers",
142
+ ],
143
+ )
144
+
145
+ cc_library(
146
+ name = "mesh",
147
+ srcs = [
148
+ "d_assert.cc",
149
+ "global_heap.cc",
150
+ "libmesh.cc",
151
+ "measure_rss.cc",
152
+ "meshable_arena.cc",
153
+ "real.cc",
154
+ "runtime.cc",
155
+ "thread_local_heap.cc",
156
+ ],
157
+ hdrs = glob([
158
+ "*.h",
159
+ "plasma/*.h",
160
+ "rng/*.h",
161
+ "gnu_wrapper.cc",
162
+ "mac_wrapper.cc",
163
+ "wrapper.cc",
164
+ "rpl_printf.c",
165
+ "static/*.h",
166
+ "size_classes.def",
167
+ ]),
168
+ copts = NO_BUILTIN_MALLOC + MESH_DEFAULT_COPTS,
169
+ defines = COMMON_DEFINES,
170
+ linkopts = COMMON_LINKOPTS + select({
171
+ "@bazel_tools//src/conditions:darwin": [
172
+ "-install_name /usr/local/lib/libmesh.dylib",
173
+ "-compatibility_version 1",
174
+ "-current_version 1",
175
+ "-ldl",
176
+ ],
177
+ "//conditions:default": [],
178
+ }),
179
+ linkstatic = False,
180
+ visibility = ["//visibility:public"],
181
+ # disabled, as we directly specify the source files above.
182
+ # this is to work around a bazel bug on macOS where if we
183
+ # specify only deps, it produces an empty dylib
184
+ # deps = [
185
+ # ":mesh-core",
186
+ # ":mesh-lib",
187
+ # ],
188
+ deps = [
189
+ "@org_heaplayers",
190
+ ],
191
+ # only valid for cc_library
192
+ alwayslink = 1,
193
+ )
194
+
195
+ cc_test(
196
+ name = "unit-tests",
197
+ srcs = glob([
198
+ "testing/unit/*.cc",
199
+ ]),
200
+ copts = [
201
+ "-Isrc",
202
+ ] + MESH_DEFAULT_COPTS,
203
+ linkopts = COMMON_LINKOPTS,
204
+ deps = [
205
+ ":mesh-core",
206
+ "@com_google_googletest//:gtest_main",
207
+ ],
208
+ )
209
+
210
+ cc_test(
211
+ name = "local-refill-benchmark",
212
+ srcs = ["testing/benchmark/local_refill.cc"],
213
+ copts = [
214
+ "-Isrc",
215
+ ] + NO_BUILTIN_MALLOC + MESH_DEFAULT_COPTS,
216
+ linkopts = COMMON_LINKOPTS,
217
+ deps = [
218
+ ":mesh-core",
219
+ "@com_google_benchmark//:benchmark",
220
+ "@com_google_googletest//:gtest_main",
221
+ ],
222
+ )