You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refactor build system: add file generation from templates, update Makefile, and enhance README. No more hardcoded ../../.. that needs manual adjusting, better portability.
Copy file name to clipboardExpand all lines: Readme.md
+18-35Lines changed: 18 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
[](https://opensource.org/licenses/MIT)
4
4
5
-
Welcome! This project provides a custom Rust compiler backend (`rustc_codegen_jvm`) that compiles Rust code into Java Virtual Machine (JVM) bytecode. This allows Rust programs to run on the JVM. Currently, the generated bytecode supports JRE 8 and later versions.
5
+
Welcome! This project provides a custom Rust compiler backend (`rustc_codegen_jvm`) that compiles Rust code into Java Virtual Machine (JVM) bytecode. This allows Rust programs to run on the JVM. Currently, the generated bytecode supports JVM 8 and later versions.
6
6
7
7
## How It Works
8
8
@@ -34,67 +34,49 @@ This backend currently supports a subset of Rust features:
*(Note: The `rust-toolchain.toml` file in the repository should handle this automatically if you use `cargo` within the project.)*
49
+
***Rust Nightly:** Ensure you are using the latest **nightly** Rust toolchain. You can set this up with `rustup default nightly`. Some rust components are needed but will be automatically installed by the Makefile.
54
50
***Java Development Kit (JDK):** A working JDK (version 8 or later recommended) is required to run the generated `.jar` files and the `asm-processor`. Make sure `java` is in your PATH.
55
51
***Gradle:** Required to build the `asm-processor` Kotlin project. Make sure `gradle` is in your PATH.
52
+
***Python 3:** Required to run the integration tests and generate files from templates. Make sure `python3` is in your PATH.
56
53
57
54
## Building the Toolchain
58
55
59
-
1. **Run Setup Script (if needed):**
60
-
* The `setup.sh` script mainly adds rustup components, which `rust-toolchain.toml` might already handle. Ensure the components listed in Prerequisites are installed.
61
-
2. **Build All Components:**
56
+
1.**Build All Components:**
62
57
* You can use the provided Makefile or build script:
63
58
```bash
64
59
# Using Make
65
60
make all
66
61
```
67
62
* This will:
68
-
* Build the main `rustc_codegen_jvm` library (`target/debug/librustc_codegen_jvm.dylib`).
63
+
* Build the main `rustc_codegen_jvm` library (`target/debug/librustc_codegen_jvm.[dll/dylib/so]`).
69
64
* Build the `java-linker` (`java-linker/target/debug/java-linker`).
70
65
* Build the `asm-processor` (`asm-processor/build/libs/asm-processor-*.jar`).
66
+
* Build the Kotlin shim of the Rust core library (`library`).
67
+
* Generate the `config.toml` and `jvm-unknown-unknown.json` files from their templates.
68
+
71
69
72
70
## Using the Toolchain (Compiling Another Rust Project)
73
71
74
72
To compile *your own* Rust project using this backend:
75
73
76
-
1. **Get the Toolchain:** Clone this repository and build it as described above. Let's assume you cloned it to `/path/to/rustc_codegen_jvm`. Ensure you build the toolchain first, as described in the previous section.
74
+
1. **Get the Toolchain:** Clone this repository and build it as described above. Ensure you build the toolchain first, as described in the previous section, by running `make all`. You will need to re-run `make gen-files`if you change the absolute path of where this repository is stored since building.
77
75
78
76
79
77
2. **Configure Your Rust Project:**
80
78
* In your *own* Rust project's directory, create a `.cargo/config.toml` file (if it doesn't exist).
# Throwing a JVM exception will unwind and give a stack trace, no need for rust to handle unwinding.
91
-
[profile.debug]
92
-
panic = "abort"
93
-
94
-
[profile.release]
95
-
panic = "abort"
96
-
```
97
-
* **Important:** Replace `/path/to/rustc_codegen_jvm/...` with the path to where you cloned the repository. If you're not on macOS, changed `.dylib` to `.so`for Linux or `.dll`for Windows.
79
+
* Copy the contents from the `config.toml` file generated specifically foryour system, that can be foundin the root of this project after running `make all`. If since running make, you've moved this repo to a different directory, you'll need to run at least `make gen-files`.
98
80
99
81
3. **Build Your Project:**
100
82
* Run the standard Cargo build command, targeting the host target (using the `jvm-unknown-unknown` target is an emerging feature and means you can't even use `core`, for now, so not recommended). Cargo will read the `.cargo/config.toml` and use the specified target and flags automatically.
@@ -117,15 +99,14 @@ To compile *your own* Rust project using this backend:
117
99
118
100
This project includes integration tests managed by a Python script.
119
101
120
-
1. **Ensure Toolchain is Built:** Build the project using `make all`.
121
-
2. **Check Target JSON:** Make sure the `jvm-unknown-unknown.json` file in the *root* of this repository has the **relative paths** starting with `/path/to/rustc_codegen_jvm/`for the linker and backend, as the tester expects this structure when running tests from subdirectories. If you changed them to absolute paths for external use, change them back temporarily.
122
-
3. **Run the Tester:**
102
+
1. **Ensure Toolchain is Built:** Build the project using `make all`. If you've changed the path of the repository, run `make gen-files` to regenerate the configuration files.
103
+
2. **Run the Tester:**
123
104
```bash
124
105
python3 Tester.py
125
106
# For release mode tests:
126
107
# python3 Tester.py --release
127
108
```
128
-
4. **Check Output:** Look forthe final "✅ All tests passed!" message. If tests fail, the script will generate `.generated` filesin the respective test directories (`tests/binary/*`) containing error details or output diffs.
109
+
3. **Check Output:** Look for the final "✅ All tests passed!" message. If tests fail, the script will generate `.generated` files in the respective test directories (`tests/binary/*`) containing error details or output diffs.
129
110
130
111
## Project Structure
131
112
@@ -141,8 +122,10 @@ This project includes integration tests managed by a Python script.
141
122
* `library/`: Source code for a minimal Kotlin-based implementation of the Rust core library. This serves as a temporary substitute to bootstrap the project until the backend can fully compile the Rust core library itself.
142
123
* `shim-metadata-gen`: A tool for generating metadata for the Kotlin core library, called at compiletime to provide nessecary info (descriptors) to the codegen backend. It's generated metadata is embedded in the generated library, so not needed at runtime.
143
124
*`core.json`: Metadata for the core library, generated by this tool.
144
-
*`jvm-unknown-unknown.json`: The Rust target specification file.
125
+
*`jvm-unknown-unknown.json.template`: The template forRust target specification file (currently experimental & not recommended, use `config.toml`in your project instead).
126
+
*`config.toml.template`: The template for the Cargo configuration file for the toolchain.
145
127
*`Tester.py`: Python script for running integration tests.
128
+
*`GenerateFiles.py`: Python script for generating the `config.toml` file and the `jvm-unknown-unknown.json` file from their templates, making them suited to your system.
146
129
*`Makefile` Scripts for building the entire toolchain.
147
130
*`setup.sh`: Script to install Rust components.
148
131
*`Cargo.toml`, `Cargo.lock`: Rust package definition and dependencies for the backend.
0 commit comments