We welcome contributions to Wasmtime4j! This document provides guidelines for contributing to the project.
This project adheres to a code of conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to wasmtime4j@tegmentum.ai.
Before creating an issue, please:
- Check if the issue already exists in the issue tracker
- Search through closed issues to see if it's already been addressed
- Check the FAQ and troubleshooting guide
When creating an issue, please include:
- Environment Information: Java version, OS, architecture
- Runtime Information: JNI or Panama, Wasmtime version
- Steps to Reproduce: Minimal code example that demonstrates the problem
- Expected vs Actual Behavior: What you expected to happen vs what actually happened
- Stack Traces: Full stack traces for exceptions or crashes
Feature requests are welcome! Please:
- Check if the feature has already been requested
- Explain the use case and why this feature would be valuable
- Consider if this feature aligns with the project's goals
- Be prepared to contribute to the implementation
- Discuss Large Changes: For significant changes, open an issue first to discuss the approach
- Check Existing Work: Look for existing pull requests that might address the same issue
- Understand the Architecture: Read the project documentation to understand the codebase
-
Fork and Clone:
git clone https://github.com/your-username/wasmtime4j.git cd wasmtime4j -
Install Prerequisites:
- Java 8+ (JNI development)
- Java 22+ (Panama development)
- Rust toolchain (latest stable)
- Maven 3.6+
-
Build and Test:
./mvnw clean compile ./mvnw test -
Verify Quality Checks:
./mvnw checkstyle:check spotless:check
-
Create a Branch:
git checkout -b feature/your-feature-name # or git checkout -b fix/issue-description -
Follow Code Style:
- The project follows the Google Java Style Guide
- Use
./mvnw spotless:applyto auto-format code - Run
./mvnw checkstyle:checkto verify compliance
-
Write Tests:
- Add unit tests for new functionality
- Ensure tests pass on both JNI and Panama implementations
- Use descriptive test names and good assertions
- Follow existing test patterns in the codebase
-
Update Documentation:
- Update README.md for user-facing changes
- Add or update Javadoc comments
- Update examples if APIs change
- Defensive Programming: Always validate inputs and handle errors gracefully
- Resource Management: Use try-with-resources and proper cleanup
- Performance: Consider performance implications, especially for JNI calls
- Compatibility: Maintain compatibility across Java versions and platforms
- Naming: Use clear, descriptive names for variables, methods, and classes
- Documentation: All public APIs must have Javadoc
- Error Handling: Use appropriate exception types from
ai.tegmentum.wasmtime4j.exception - Logging: Use
java.util.logging.Loggerfor logging - Final Parameters: Method parameters should be declared
final
-
Module Separation:
wasmtime4j: Public API only, no implementation detailswasmtime4j-jni: JNI-specific implementationwasmtime4j-panama: Panama-specific implementationwasmtime4j-native: Shared Rust native code
-
Interface Design:
- Keep interfaces simple and focused
- Use factory patterns for object creation
- Implement
AutoCloseablefor resource management
-
Native Code:
- All native methods must be defensive
- Handle all native errors gracefully
- Never allow native crashes to propagate to JVM
-
Test Coverage:
- Aim for high test coverage on public APIs
- Test error conditions and edge cases
- Test both JNI and Panama implementations
-
Test Organization:
- Unit tests in
src/test/java - Integration tests in
wasmtime4j-tests - Benchmarks in
wasmtime4j-benchmarks
- Unit tests in
-
Test Naming:
// Good void testEngineCreationWithValidConfig() void testModuleCompilationWithInvalidBytecode() // Bad void test1() void testEngine()
-
Commit Guidelines:
- Use Conventional Commits format
- Write clear, descriptive commit messages
- Keep commits focused and atomic
Examples:
feat(api): add fuel consumption support to Store interface fix(jni): prevent memory leak in module compilation docs(readme): update installation instructions for Maven test(benchmarks): add memory operation benchmarks -
Before Submitting:
# Ensure everything builds ./mvnw clean compile # Run all tests ./mvnw test # Check code quality ./mvnw checkstyle:check spotless:check # Verify no regressions in benchmarks (if applicable) ./mvnw -pl wasmtime4j-benchmarks test
-
Pull Request Description:
- Reference related issues using
Fixes #123orCloses #123 - Describe what changes were made and why
- Mention any breaking changes
- Include testing notes for reviewers
- Reference related issues using
-
Pull Request Template:
## Summary Brief description of changes ## Changes Made - List of specific changes - Include breaking changes ## Testing - How you tested these changes - Any new test cases added ## Related Issues - Fixes #123 - Related to #456
- Automated Checks: All PRs must pass CI checks (build, tests, quality)
- Code Review: At least one maintainer will review your changes
- Testing: Changes will be tested on multiple platforms and Java versions
- Feedback: Address reviewer feedback promptly and courteously
Releases follow semantic versioning (SemVer):
- MAJOR: Breaking API changes
- MINOR: New features, backward compatible
- PATCH: Bug fixes, backward compatible
-
IDE Setup:
- IntelliJ IDEA or Eclipse recommended
- Import as Maven project
- Install Checkstyle plugin
- Configure auto-formatting with Google Java Style
-
Git Configuration:
git config --local core.autocrlf input git config --local pull.rebase true
- Add interface to
wasmtime4jmodule - Implement in both
wasmtime4j-jniandwasmtime4j-panama - Add corresponding native code if needed
- Write comprehensive tests
- Update documentation and examples
- Write a failing test that reproduces the bug
- Implement the fix
- Ensure the test passes
- Check for similar issues in other parts of the codebase
- Add benchmarks to measure current performance
- Implement improvements
- Verify benchmarks show improvement
- Check that accuracy is maintained
- Native methods are declared in Java classes
- Implementation goes in
wasmtime4j-native/src/jni/ - Use defensive programming in native code
- Test on multiple platforms
- Use Panama FFI for Java 22+
- Implementation goes in
wasmtime4j-panama - Leverage shared native library from
wasmtime4j-native - Handle preview feature requirements
# Build native library
cd wasmtime4j-native
cargo build --release
# Cross-compile for different platforms
cargo build --release --target x86_64-pc-windows-gnu
cargo build --release --target aarch64-apple-darwinThe project uses a centralized version management system. All version definitions are derived from a single source of truth.
- Source of Truth:
wasmtime-version.properties - Maven: Uses CI-friendly versions with
${revision}=${wasmtime.version}-${wasmtime4j.version} - Cargo: Uses workspace dependencies defined in root
Cargo.toml
-
Update the properties file (
wasmtime-version.properties):wasmtime.version=41.0.4 wasmtime4j.version=1.0.0 wasmtime.fork.branch=fix/global-code-registry-idempotent-v41
-
Run the sync script to propagate changes:
./scripts/sync-wasmtime-version.sh
-
Verify consistency:
./scripts/check-version-consistency.sh
-
Update Cargo.lock:
cargo update
-
Update the fork branch (if needed):
- If the SIGABRT fix is not yet in the new Wasmtime version, rebase the tegmentum/wasmtime fork
- Update
wasmtime.fork.branchin the properties file - Re-run the sync script
-
Build and test:
cargo build --release cargo test ./mvnw clean test -q
The sync script updates the following files:
Cargo.toml(workspace) - wasmtime dependency versionswasmtime4j-native/Cargo.toml- package versionwasmtime4j-native/src/lib.rs-WASMTIME_VERSIONconstantpom.xml-wasmtime.versionandwasmtime4j.versionproperties
Child pom.xml files use ${revision} and don't need manual updates.
- Wasmtime version: Follows upstream Wasmtime releases (e.g.,
41.0.3) - Wasmtime4j version: Our binding version (e.g.,
1.0.0) - Full version:
${wasmtime.version}-${wasmtime4j.version}(e.g.,41.0.3-1.0.0)
- GitHub Issues: Bug reports and feature requests
- GitHub Discussions: General questions and community discussion
- Mailing List: Development announcements and coordination
If you need help while contributing:
- Check the wiki
- Ask questions in GitHub Discussions
- Reach out to maintainers via email
Contributors will be:
- Listed in the CONTRIBUTORS.md file
- Mentioned in release notes for significant contributions
- Given appropriate credit in documentation and examples
By contributing to Wasmtime4j, you agree that your contributions will be licensed under the same license as the project (MIT License).
Thank you for contributing to Wasmtime4j! Your contributions help make WebAssembly more accessible to the Java community.