Spaces:
Sleeping
Sleeping
Commit
·
40a23ca
1
Parent(s):
0406cd0
Improve Rust
Browse files- execute.py +11 -4
execute.py
CHANGED
|
@@ -255,15 +255,22 @@ def unsafe_execute_rust(check_program, result, timeout):
|
|
| 255 |
os.makedirs(RUST_BIN, exist_ok=True)
|
| 256 |
|
| 257 |
# Check if Cargo exists, if so copy it here
|
| 258 |
-
if os.path.exists("
|
| 259 |
-
shutil.copy("
|
| 260 |
else:
|
| 261 |
# Warn that no Cargo was found in the parent directory
|
| 262 |
-
logging.warning(f"Cargo.toml not found in {os.path.abspath('
|
| 263 |
# Create Cargo.toml
|
| 264 |
open(f"{RUST_DIR}/Cargo.toml", 'w').write(BASE_CARGO)
|
| 265 |
|
| 266 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
|
| 268 |
compilation_result = subprocess.run(["cargo", "check", "--bin", "test", "--message-format", "json"], capture_output=True)
|
| 269 |
if compilation_result.returncode == 0:
|
|
|
|
| 255 |
os.makedirs(RUST_BIN, exist_ok=True)
|
| 256 |
|
| 257 |
# Check if Cargo exists, if so copy it here
|
| 258 |
+
if os.path.exists("/Cargo.toml"):
|
| 259 |
+
shutil.copy("/Cargo.toml", RUST_DIR)
|
| 260 |
else:
|
| 261 |
# Warn that no Cargo was found in the parent directory
|
| 262 |
+
logging.warning(f"Cargo.toml not found in root directory ({os.path.abspath('/')}). Creating a new one. Timeout of >300 is recommended.")
|
| 263 |
# Create Cargo.toml
|
| 264 |
open(f"{RUST_DIR}/Cargo.toml", 'w').write(BASE_CARGO)
|
| 265 |
|
| 266 |
+
with tempfile.NamedTemporaryFile(dir = RUST_BIN, delete=False) as f:
|
| 267 |
+
file_name: str = "test" + RUST_EXT
|
| 268 |
+
os.rename(f.name, os.path.join(RUST_BIN, file_name))
|
| 269 |
+
# Dump the rust source code in the target temporal file
|
| 270 |
+
f.write(check_program.encode('utf-8'))
|
| 271 |
+
|
| 272 |
+
# Proceed towards Rust binaries compilation. Therefore move to Rust module root dir.
|
| 273 |
+
os.chdir(RUST_DIR)
|
| 274 |
|
| 275 |
compilation_result = subprocess.run(["cargo", "check", "--bin", "test", "--message-format", "json"], capture_output=True)
|
| 276 |
if compilation_result.returncode == 0:
|