|
| 1 | +# Copyright 2026 Google LLC |
| 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 at |
| 6 | +# |
| 7 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +"""Repository rule to probe compiler support for SFrame flags.""" |
| 16 | + |
| 17 | +def _compiler_probe_impl(repository_ctx): |
| 18 | + # Try to determine the compiler. Prefer CC from environment. |
| 19 | + cc = repository_ctx.os.environ.get("CC", "c++") |
| 20 | + |
| 21 | + # Run a test compilation to test if the flag is recognized. |
| 22 | + # This is hacky and I wish there was a better way. |
| 23 | + res = repository_ctx.execute([ |
| 24 | + cc, |
| 25 | + "-Wa,--gsframe=no", |
| 26 | + "-c", |
| 27 | + "-x", |
| 28 | + "c++", |
| 29 | + "/dev/null", |
| 30 | + "-o", |
| 31 | + "/dev/null", |
| 32 | + ]) |
| 33 | + |
| 34 | + supports_gsframe = (res.return_code == 0) |
| 35 | + |
| 36 | + repository_ctx.file("BUILD.bazel", "package(default_visibility = ['//visibility:public'])\n") |
| 37 | + repository_ctx.file("compiler_config.bzl", "SUPPORTS_GSFRAME = %s\n" % supports_gsframe) |
| 38 | + |
| 39 | +compiler_probe = repository_rule( |
| 40 | + implementation = _compiler_probe_impl, |
| 41 | + local = True, |
| 42 | + environ = ["CC", "PATH"], |
| 43 | +) |
0 commit comments