1111import os
1212import re
1313import shutil
14- import tomli
1514
1615
1716MODELS = ("refcount" , "unsafe" )
@@ -42,12 +41,6 @@ def matches(match):
4241 if models is None or models .strip () == "" :
4342 return True
4443 return model in re .split (r"\s*,\s*" , models .strip ())
45- os .path .join (os .path .dirname (__file__ ), "../../../../build/tmp/cargo-target" )
46- )
47-
48-
49- def cargo_env ():
50- return dict (os .environ , CARGO_TARGET_DIR = os .path .abspath (shared_target_dir ()))
5144
5245 xfail_m = RE_XFAIL .search (text )
5346 xfail = xfail_m is not None and model in re .split (r"\s*,\s*" , xfail_m .group (1 ))
@@ -199,18 +192,13 @@ def build_cpp(self):
199192
200193 def build_rust (self ):
201194 exp = self .expectations
202- rust_version = read_rust_version ()
203195 self .pkg_name = "test_" + re .sub (r"[^a-zA-Z0-9_]" , "_" , self .tmp_dir .name )
204196
205- (self .tmp_dir / "rust-toolchain.toml" ).write_text (
206- f'[toolchain]\n channel = "{ rust_version } "\n '
207- )
208197 (self .tmp_dir / "Cargo.toml" ).write_text (f"""
209198[package]
210199name = "{ self .pkg_name } "
211200version = "0.1.0"
212201edition = "2021"
213- rust-version = "{ rust_version } "
214202
215203[[bin]]
216204name = "{ self .pkg_name } "
@@ -221,7 +209,7 @@ def build_rust(self):
221209libcc2rs = {{ path = "../../../libcc2rs" }}
222210""" )
223211
224- cmd = ["cargo" , "build" , "--release" , "--quiet" ]
212+ cmd = ["cargo" , "+" + read_rust_version (), " build" , "--release" , "--quiet" ]
225213 _ , err , returncode = lit .util .executeCommand (
226214 cmd , str (self .tmp_dir ), env = cargo_env ()
227215 )
@@ -332,8 +320,15 @@ def getTestsInDirectory(self, testSuite, path_in_suite, litConfig, localConfig):
332320
333321
334322def read_rust_version ():
335- toolchain_path = Path (__file__ ).parent / "../../../../libcc2rs/rust-toolchain.toml"
336- return tomli .loads (toolchain_path .read_text ())["toolchain" ]["channel" ]
323+ toolchain_path = os .path .join (
324+ os .path .dirname (__file__ ), "../../../../cmake/rust-toolchain.cmake"
325+ )
326+ with open (toolchain_path , "r" ) as f :
327+ for line in f :
328+ m = re .match (r'set\(RUST_STABLE_VERSION\s+"([^"]+)' , line )
329+ if m :
330+ return m .group (1 )
331+ raise Exception ("could not find rust version in " + toolchain_path )
337332
338333
339334def shared_target_dir ():
0 commit comments