Skip to content

Commit baa89e5

Browse files
committed
Support for all tests passing in release mode (the CI now checks this too).
Some needed changes in lower1/lower2 and new shims to support this. Replaced uses of String with &str as String is part of alloc (we are just trying to support core for now). Added debug/release modes to java-linker. Added confirming release mode works to CI script.
1 parent ba9dda4 commit baa89e5

File tree

31 files changed

+647
-223
lines changed

31 files changed

+647
-223
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,9 @@ jobs:
5252
run: make ci # Use your optimized CI build command
5353

5454
# 10. Run tests
55-
- name: Run integration tests
56-
run: python3 Tester.py
55+
- name: Run integration tests (debug mode)
56+
run: python3 Tester.py
57+
58+
# 11. Run tests in release mode
59+
- name: Run integration tests (release mode)
60+
run: python3 Tester.py --release

Cargo.lock

Lines changed: 24 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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ edition = "2024"
66
[dependencies]
77
bigdecimal = "0.4.8"
88
half = "2.6.0"
9+
libc = "0.2.172"
910
num-bigint = "0.4.6"
1011
num-traits = "0.2.19"
1112
regex = "1.11.1"
1213
ristretto_classfile = { version = "0.16.0" }
1314
serde = { version = "1.0.219", features = ["derive"] }
1415
serde_json = "1.0.140"
1516
sha2 = "0.10.8"
17+
zerocopy = "0.8.25"
1618

1719
[lib]
1820
crate-type = ["dylib"]

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,6 @@ clean-vendor-r8:
134134

135135
# === Clean All ===
136136
clean: clean-rust clean-java-linker clean-library clean-shim-metadata-gen clean-gen-files clean-vendor-r8
137-
@echo "$(GREEN)🧼 All clean!$(RESET)"
137+
@echo "$(GREEN)🧼 All clean!$(RESET)"
138+
139+
rebuild-shim: clean-library library shim-metadata-gen/core.json rust

Readme.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ All examples live in `tests/binary` and are compiled to JVM bytecode & run/teste
5050
- Structs, tuples, enums (both C‑like and Rust‑style)
5151
- Executable `.jar` generation for binary crates
5252
- Mutable borrowing, references, and dereferencing
53-
- **Integration tests** for all features
53+
- **Integration tests** for all features, in debug and release modes
5454

5555
🚧 **Next Milestone:** Full support for the Rust `core` crate.
5656

@@ -117,12 +117,16 @@ make gen-files
117117
## 🚀 Usage
118118

119119
1. **Configure your project**
120-
In *your* Rust project directory, create or update `.cargo/config.toml` with the generated template (will be at the root of this repo after running make).
120+
In *your* Rust project directory, create or update `.cargo/config.toml` by copying the generated template (will be at the root of this repo after running make). Also, your `Cargo.toml` needs to contain the following (used to pass flags differentiating between debug and release builds to the linker):
121+
122+
```toml
123+
cargo-features = ["profile-rustflags"]
124+
```
121125

122126
2. **Build with Cargo**
123127
```bash
124128
cargo build # debug
125-
cargo build --release # optimized - functionality available slightly impaired
129+
cargo build --release # optimized
126130
```
127131

128132
3. **Run the `.jar`**

Tester.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ def process_test(test_dir: str, release_mode: bool):
8383
print(f"|---- ❌ java exited with code {proc.returncode}")
8484
return False
8585

86-
expected_file = os.path.join(test_dir, "java-output.expected")
86+
expected_file = os.path.join(test_dir, "java-output.release.expected") if release_mode else os.path.join(test_dir, "java-output.expected")
87+
if not os.path.exists(expected_file) and release_mode:
88+
expected_file = os.path.join(test_dir, "java-output.expected")
89+
8790
if os.path.exists(expected_file):
8891
expected_output = read_from_file(expected_file)
8992
if expected_output.strip() == "":

config.toml.template

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ rustflags = [
1010
panic = "abort"
1111

1212
[profile.release]
13-
panic = "abort"
13+
panic = "abort"
14+
rustflags = [
15+
"-C", "link-args=--release"
16+
]

java-linker/src/main.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ fn main() -> Result<(), i32> {
3434
let mut output_file: Option<String> = None;
3535
let mut r8_jar_path: Option<PathBuf> = None;
3636
let mut proguard_config_path: Option<PathBuf> = None;
37+
let mut release_mode = false; // Default to false, can be set by a flag
3738
let java_lib_path: Option<PathBuf> = env::var("JAVA_HOME").ok().map(PathBuf::from);
3839

3940

@@ -71,6 +72,9 @@ fn main() -> Result<(), i32> {
7172
);
7273
return Err(1);
7374
}
75+
} else if arg == "--release" {
76+
release_mode = true; // Set release mode
77+
i += 1;
7478
} else if !arg.starts_with('-') {
7579
// Collect potential input files, differentiating classes and JARs
7680
if arg.ends_with(".class") {
@@ -174,6 +178,7 @@ fn main() -> Result<(), i32> {
174178
r8_jar_path.as_deref(),
175179
proguard_config_path.as_deref(),
176180
java_lib_path.as_deref(),
181+
release_mode,
177182
).map_err(|e| {
178183
eprintln!("Error creating JAR file: {}", e);
179184
1 // Propagate error code
@@ -354,6 +359,7 @@ fn create_jar(
354359
r8_jar_path: Option<&Path>,
355360
proguard_config_path: Option<&Path>,
356361
java_lib_path: Option<&Path>, // Base Java runtime lib path
362+
release_mode: bool
357363
) -> io::Result<()> {
358364
// Regex for stripping cargo hashes from .class filenames
359365
let re_strip_hash = Regex::new(r"^(?P<name>[^-]+)(?:-[0-9a-fA-F]+)?\.class$").unwrap();
@@ -466,6 +472,7 @@ fn create_jar(
466472
&intermediate_jar_path, // Program input
467473
&library_jar_paths, // Additional libs
468474
&optimized_jar_path, // Output
475+
release_mode, // Release mode flag
469476
) {
470477
Ok(_) => {
471478
println!("R8 optimization successful. Output: {}", optimized_jar_path.display());
@@ -642,6 +649,7 @@ fn run_r8_optimizer(
642649
program_input_jar_path: &Path, // The intermediate JAR with app classes
643650
library_jar_paths: &[PathBuf], // List of other input JARs (dependencies)
644651
output_jar_path: &Path, // Where R8 should write the optimized JAR
652+
release_mode: bool, // Release mode flag
645653
) -> io::Result<()> {
646654
println!("--- Running R8 ---");
647655
println!(" R8 JAR: {}", r8_jar_path.display());
@@ -662,7 +670,6 @@ fn run_r8_optimizer(
662670
.arg(r8_jar_path) // Provide path to r8.jar
663671
.arg(r8_main_class) // Specify the main class to run
664672
// --- R8 specific arguments ---
665-
.arg("--release") // Enable release mode (optimizations, shrinking)
666673
.arg("--output") // Specify output path
667674
.arg(output_jar_path)
668675
.arg("--pg-conf") // Specify ProGuard/R8 config file
@@ -677,6 +684,10 @@ fn run_r8_optimizer(
677684
cmd.arg("--classpath").arg(lib_path);
678685
}
679686

687+
if release_mode {
688+
cmd.arg("--release"); // Add release mode flag if specified
689+
}
690+
680691
// Add the program input JAR (containing app classes) last
681692
cmd.arg(program_input_jar_path);
682693

0 commit comments

Comments
 (0)