99import re
1010import shutil
1111import random
12- import tomli
1312
1413
1514def read_rust_version ():
1615 toolchain_path = os .path .join (
17- os .path .dirname (__file__ ), "../../../../libcc2rs /rust-toolchain.toml "
16+ os .path .dirname (__file__ ), "../../../../cmake /rust-toolchain.cmake "
1817 )
19- with open (toolchain_path , "rb" ) as f :
20- return tomli .load (f )["toolchain" ]["channel" ]
18+ with open (toolchain_path , "r" ) as f :
19+ for line in f :
20+ m = re .match (r'set\s*\(\s*RUST_VERSION\s+"([^"]+)' , line )
21+ if m :
22+ return m .group (1 )
23+ raise Exception ("could not find rust version in " + toolchain_path )
2124
2225
2326def shared_target_dir ():
@@ -170,15 +173,12 @@ def fail(str, code=fail_code):
170173 pkg_name = "test_" + re .sub (r"[^a-zA-Z0-9_]" , "_" , os .path .basename (tmp_dir ))
171174
172175 # Check if we can compile the rust file
173- with open (tmp_dir + "/rust-toolchain.toml" , "w" ) as f :
174- f .write (f'[toolchain]\n channel = "{ self .rust_version } "\n ' )
175176 with open (tmp_dir + "/Cargo.toml" , "w" ) as f :
176177 f .write (f"""
177178[package]
178179name = "{ pkg_name } "
179180version = "0.1.0"
180181edition = "2021"
181- rust-version = "{ self .rust_version } "
182182
183183[[bin]]
184184name = "{ pkg_name } "
@@ -189,7 +189,7 @@ def fail(str, code=fail_code):
189189libcc2rs = {{ path = "../../../libcc2rs" }}
190190""" )
191191
192- cmd = ["cargo" , "build" , "--release" , "--quiet" ]
192+ cmd = ["cargo" , "+" + self . rust_version , " build" , "--release" , "--quiet" ]
193193 _ , err , returncode = lit .util .executeCommand (cmd , tmp_dir , env = cargo_env ())
194194 if should_not_compile :
195195 if returncode != 0 :
0 commit comments