Skip to content

Commit 3f4bcbf

Browse files
authored
Export compiler related constants from CMake (#196)
Fixes #115
1 parent 8f79a34 commit 3f4bcbf

4 files changed

Lines changed: 21 additions & 6 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# CMake
22
build/
3+
_buildconfig.py
34

45
# Cargo
56
target/

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ execute_process(
5050
)
5151
message(STATUS ${CLANG_OUTPUT})
5252

53+
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/generate-buildconfig-py.cmake)
54+
generate_buildconfig_py("${CMAKE_CURRENT_SOURCE_DIR}/tests/lit/lit")
55+
5356
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/rust-toolchain.cmake)
5457
set(RUST_STAMP_FILE "${CMAKE_BINARY_DIR}/.rust-toolchain.stamp")
5558

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function(generate_buildconfig_py outdir)
2+
file(CONFIGURE
3+
OUTPUT "${outdir}/_buildconfig.py"
4+
CONTENT [[
5+
"""Generated by CMake, do not edit."""
6+
7+
from pathlib import Path
8+
9+
CXX = Path(r"@CMAKE_CXX_COMPILER@")
10+
CC = Path(r"@CMAKE_C_COMPILER@")
11+
]]
12+
ESCAPE_QUOTES
13+
@ONLY
14+
)
15+
endfunction()

tests/lit/lit/formats/Cpp2RustTest.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import lit.Test
55
import lit.util
6+
from .._buildconfig import CXX, CC
67
from .base import TestFormat
78
from dataclasses import dataclass
89
from pathlib import Path
@@ -177,12 +178,7 @@ def build_cpp(self):
177178
self.cpp_bin = self.build_dir / "app"
178179
return None
179180

180-
## FIXME: these must use the detected/chosen compiler in cmake
181-
cc = (
182-
os.environ.get("CC", "clang")
183-
if self.cc_input.suffix == ".c"
184-
else os.environ.get("CXX", "clang++")
185-
)
181+
cc = CC if self.cc_input.suffix == ".c" else CXX
186182
self.cpp_bin = self.tmp_dir / "cpp"
187183
cmd = [
188184
cc,

0 commit comments

Comments
 (0)