@@ -13,6 +13,14 @@ def read_rust_version():
1313 with open (toolchain_path , 'rb' ) as f :
1414 return tomli .load (f )['toolchain' ]['channel' ]
1515
16+ def shared_target_dir ():
17+ return os .path .abspath (os .path .join (
18+ os .path .dirname (__file__ ),
19+ '../../../../build/tmp/cargo-target' ))
20+
21+ def cargo_env ():
22+ return dict (os .environ , CARGO_TARGET_DIR = os .path .abspath (shared_target_dir ()))
23+
1624class Cpp2RustTest (TestFormat ):
1725 def __init__ (self ):
1826 self .regex_xfail = re .compile (r"//\s*XFAIL:\s*(.*)" )
@@ -120,24 +128,31 @@ def fail(str, code = fail_code):
120128 fromfile = 'expected' , tofile = 'generated' ))
121129 return fail ('different output\n ' + diff )
122130
131+ pkg_name = "test_" + re .sub (r'[^a-zA-Z0-9_]' , '_' , os .path .basename (tmp_dir ))
132+
123133 # Check if we can compile the rust file
124134 with open (tmp_dir + "/rust-toolchain.toml" , 'w' ) as f :
125135 f .write (f'[toolchain]\n channel = "{ self .rust_version } "\n ' )
126136 with open (tmp_dir + "/Cargo.toml" , 'w' ) as f :
127137 f .write (f"""
128138[package]
129- name = "test "
139+ name = "{ pkg_name } "
130140version = "0.1.0"
131141edition = "2021"
132142rust-version = "{ self .rust_version } "
133143
144+ [[bin]]
145+ name = "{ pkg_name } "
146+ path = "src/main.rs"
147+
134148[dependencies]
135149libc = "0.2.169"
136150libcc2rs = {{ path = "../../../libcc2rs" }}
151+ rules = {{ path = "../../../rules" }}
137152""" )
138153
139154 cmd = ['cargo' , 'build' , '--release' , '--quiet' ]
140- _ , err , returncode = lit .util .executeCommand (cmd , tmp_dir )
155+ _ , err , returncode = lit .util .executeCommand (cmd , tmp_dir , env = cargo_env () )
141156 if should_not_compile :
142157 if returncode != 0 :
143158 shutil .rmtree (tmp_dir , True )
@@ -146,7 +161,7 @@ def fail(str, code = fail_code):
146161 if returncode != 0 :
147162 return fail ('cargo failed\n ' + err )
148163
149- rust_bin = tmp_dir + "/target/ release/test"
164+ rust_bin = os . path . join ( shared_target_dir (), " release" , pkg_name )
150165
151166 if not skip_run :
152167 if should_panic :
0 commit comments