Skip to content

Commit 2d5effb

Browse files
committed
Massive overhaul, supports more complex programs now
1 parent 384e03b commit 2d5effb

File tree

14 files changed

+1598
-385
lines changed

14 files changed

+1598
-385
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.1.0"
44
edition = "2024"
55

66
[dependencies]
7-
ristretto_classfile = { version = "0.14.0" }
7+
ristretto_classfile = { version = "0.16.0" }
88

99
[lib]
1010
crate-type = ["dylib"]

Tester.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ def process_test(test_dir: str):
3636

3737
# Run cargo build.
3838
print("|--- ⚒️ Building with Cargo...")
39-
proc = run_command(["cargo", "build", "--target", "../../../jvm-unknown-unknown.json"], cwd=test_dir)
39+
# see if the file no_jvm_target.flag exists in the test directory
40+
no_jvm_target = os.path.join(test_dir, "no_jvm_target.flag")
41+
if os.path.exists(no_jvm_target):
42+
print("|---- ⚠️ Skipping JVM target build due to no_jvm_target.flag")
43+
proc = run_command(["cargo", "build"], cwd=test_dir)
44+
else:
45+
print("|---- 🛠️ Building with JVM target...")
46+
proc = run_command(["cargo", "build", "--target", "../../../jvm-unknown-unknown.json"], cwd=test_dir)
4047
if proc.returncode != 0:
4148
fail_path = os.path.join(test_dir, "cargo-build-fail.generated")
4249
output = f"STDOUT:\n{proc.stdout}\n\nSTDERR:\n{proc.stderr}"
@@ -46,6 +53,24 @@ def process_test(test_dir: str):
4653

4754
# Run java with the generated jar.
4855
print("|--- 🤖 Running with Java...")
56+
# if no_jvm_target flag is set, we first need to move target/debug/deps/{test_name}-{hash}.jar to target/jvm-unknown-unknown/debug/{test_name}.jar
57+
# we might need to make the directory first
58+
if os.path.exists(no_jvm_target):
59+
print("|---- ⚠️ Doing some needed moving around due to no_jvm_target.flag")
60+
# move the jar file to the target/jvm-unknown-unknown/debug directory
61+
jar_path = os.path.join(test_dir, "target", "debug", "deps", f"{test_name}-*.jar")
62+
# find the jar file
63+
jar_file = None
64+
for file in os.listdir(os.path.join(test_dir, "target", "debug", "deps")):
65+
if file.startswith(test_name) and file.endswith(".jar"):
66+
jar_file = file
67+
break
68+
if jar_file is None:
69+
print("|---- ❌ No jar file found in target/debug/deps")
70+
return False
71+
# move the file
72+
os.makedirs(os.path.join(test_dir, "target", "jvm-unknown-unknown", "debug"), exist_ok=True)
73+
os.rename(os.path.join(test_dir, "target", "debug", "deps", jar_file), os.path.join(test_dir, "target", "jvm-unknown-unknown", "debug", f"{test_name}.jar"))
4974
jar_path = os.path.join(test_dir, "target", "jvm-unknown-unknown", "debug", f"{test_name}.jar")
5075
proc = run_command(["java", "-jar", jar_path])
5176
if proc.returncode != 0:

java-linker/src/main.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn main() -> Result<(), i32> {
2828
eprintln!("Error: -o flag requires an output file path");
2929
return Err(1);
3030
}
31-
} else if !arg.starts_with("-Wl") && arg != "-no-pie" && arg != "-nodefaultlibs" {
31+
} else if !arg.starts_with("-") && (arg.ends_with(".class") || arg.ends_with(".jar")) {
3232
input_files.push(arg.clone());
3333
i += 1;
3434
} else {
@@ -41,6 +41,14 @@ fn main() -> Result<(), i32> {
4141
return Err(1);
4242
}
4343

44+
// if output_file doesn't end in .jar, add .jar
45+
if let Some(ref path) = output_file {
46+
if !path.ends_with(".jar") {
47+
eprintln!("Warning: Output file should end with .jar. Adding .jar extension.");
48+
output_file = Some(format!("{}.jar", path));
49+
}
50+
}
51+
4452
let output_file_path = match output_file {
4553
Some(path) => path,
4654
None => {

0 commit comments

Comments
 (0)