diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 6e302f18de..bc0a555340 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -9,7 +9,7 @@ updates: patterns: - "*" - package-ecosystem: 'maven' - directory: '/java-wasm' + directory: '/java/wasm' schedule: interval: 'weekly' groups: diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index e3fc52303c..5aba27ce9a 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -36,8 +36,7 @@ jobs: - name: Check C coverage run: doxygen Doxyfile - name: Check Java coverage - run: javadoc -Xdoclint:all,-missing -d ../doc/java -subpackages * - working-directory: java + run: javadoc -Xdoclint:all,-missing -d doc/java -sourcepath java/api/target/generated-sources/java/:java/api/src/main/java org.ruby_lang.prism - name: Generate Rust documentation run: | bundle exec rake cargo:build diff --git a/.github/workflows/github-pages.yml b/.github/workflows/github-pages.yml index 217af4a47b..45a5418bb7 100644 --- a/.github/workflows/github-pages.yml +++ b/.github/workflows/github-pages.yml @@ -52,7 +52,7 @@ jobs: run: doxygen Doxyfile - name: Build with JavaDoc run: javadoc -Xdoclint:all,-missing -d ../doc/java -subpackages * - working-directory: java + working-directory: java/api - name: Build with rustdoc run: | bundle exec rake cargo:build diff --git a/.github/workflows/java-wasm-bindings.yml b/.github/workflows/java-wasm-bindings.yml index e3919472c3..3f39c7a1d6 100644 --- a/.github/workflows/java-wasm-bindings.yml +++ b/.github/workflows/java-wasm-bindings.yml @@ -8,7 +8,7 @@ on: - "src/" - "*akefile*" - "java/" - - "java-wasm/" + - "java/wasm/" branches: - main - ruby-4.0 @@ -44,11 +44,15 @@ jobs: java-version: '21' cache: maven - - name: Run the tests - run: mvn -B install - working-directory: java-wasm + - name: Build the Java artifacts + run: mvn -ntp install + working-directory: java + + - name: Run the tests from the WASM module + run: mvn -ntp test + working-directory: java - uses: actions/upload-artifact@v7 with: name: prism.wasm - path: java-wasm/src/test/resources/prism.wasm + path: java/wasm/src/test/resources/prism.wasm diff --git a/.gitignore b/.gitignore index 516e30de3e..fcdec6fb0a 100644 --- a/.gitignore +++ b/.gitignore @@ -42,7 +42,7 @@ out.svg /java/org/ruby_lang/prism/AbstractNodeVisitor.java /java/org/ruby_lang/prism/Loader.java /java/org/ruby_lang/prism/Nodes.java -/java-wasm/src/test/resources/prism.wasm +/java/wasm/src/test/resources/prism.wasm /lib/prism/compiler.rb /lib/prism/dispatcher.rb /lib/prism/dot_visitor.rb diff --git a/Makefile b/Makefile index d6d07943c3..039efee72c 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ all: shared static shared: build/libprism.$(SOEXT) static: build/libprism.a wasm: javascript/src/prism.wasm -java-wasm: java-wasm/src/test/resources/prism.wasm +java-wasm: java/wasm/src/test/resources/prism.wasm build/libprism.$(SOEXT): $(SHARED_OBJECTS) $(ECHO) "linking $@ with $(CC)" @@ -51,7 +51,7 @@ javascript/src/prism.wasm: Makefile $(SOURCES) $(HEADERS) -Oz -g0 -flto -fdata-sections -ffunction-sections \ -o $@ $(SOURCES) -java-wasm/src/test/resources/prism.wasm: Makefile $(SOURCES) $(HEADERS) +java/wasm/src/test/resources/prism.wasm: Makefile $(SOURCES) $(HEADERS) $(ECHO) "building $@" $(Q) $(MAKEDIRS) $(@D) $(Q) $(WASI_SDK_PATH)/bin/clang \ diff --git a/README.md b/README.md index 0805698d93..a4a9b6d340 100644 --- a/README.md +++ b/README.md @@ -29,8 +29,10 @@ The repository contains the infrastructure for both a shared library (libprism) ├── include │   ├── prism header files for the shared library │   └── prism.h main header file for the shared library -├── java Java bindings for the shared library -├── java-wasm Java WASM bindings for the shared library +├── java +| ├── api Java API for Prism +| ├── native Java native bindings for the shared library +| └── wasm Java WASM bindings for the shared library ├── javascript JavaScript WASM bindings for the shared library ├── lib │   ├── prism Ruby library files diff --git a/Rakefile b/Rakefile index 80b00bd913..eb96249985 100644 --- a/Rakefile +++ b/Rakefile @@ -43,7 +43,7 @@ elsif RUBY_ENGINE == "jruby" # This compiles java to make sure any templating changes produces valid code. Rake::JavaExtensionTask.new(:compile) do |ext| ext.name = "prism" - ext.ext_dir = "java" + ext.ext_dir = "java/api" ext.lib_dir = "tmp" ext.release = "21" ext.gem_spec = Gem::Specification.load("prism.gemspec") @@ -54,7 +54,7 @@ end CLOBBER.concat(Prism::Template::TEMPLATES) CLOBBER.concat(["build"]) CLOBBER << "lib/prism/prism.#{RbConfig::CONFIG["DLEXT"]}" -CLOBBER << "java-wasm/src/main/resources/prism.wasm" +CLOBBER << "java/wasm/src/main/resources/prism.wasm" Prism::Template::TEMPLATES.each do |filepath| desc "Generate #{filepath}" diff --git a/docs/configuration.md b/docs/configuration.md index 30001b7db7..4b23b7f46d 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -8,9 +8,9 @@ A lot of code in prism's repository is templated from a single configuration fil * `include/prism/node_new.h` - for defining the functions that create the nodes in C * `javascript/src/deserialize.js` - for defining how to deserialize the nodes in JavaScript * `javascript/src/nodes.js` - for defining the nodes in JavaScript -* `java/org/ruby_lang/prism/AbstractNodeVisitor.java` - for defining the visitor interface for the nodes in Java -* `java/org/ruby_lang/prism/Loader.java` - for defining how to deserialize the nodes in Java -* `java/org/ruby_lang/prism/Nodes.java` - for defining the nodes in Java +* `java/api/target/generated-sources/java/org/ruby_lang/prism/AbstractNodeVisitor.java` - for defining the visitor interface for the nodes in Java +* `java/api/target/generated-sources/java/org/ruby_lang/prism/Loader.java` - for defining how to deserialize the nodes in Java +* `java/api/target/generated-sources/java/org/ruby_lang/prism/Nodes.java` - for defining the nodes in Java * `lib/prism/compiler.rb` - for defining the compiler for the nodes in Ruby * `lib/prism/dispatcher.rb` - for defining the dispatch visitors for the nodes in Ruby * `lib/prism/dot_visitor.rb` - for defining the dot visitor for the nodes in Ruby diff --git a/java-wasm/README.md b/java-wasm/README.md deleted file mode 100644 index 47aa48a774..0000000000 --- a/java-wasm/README.md +++ /dev/null @@ -1,29 +0,0 @@ -This dir contains the chicory-prism artifact, a version of prism compiled to WASM and then AOT compiled to JVM bytecode by the Chicory project. - -## Building - -Generate the templated sources: - -``` -PRISM_EXCLUDE_PRETTYPRINT=1 PRISM_SERIALIZE_ONLY_SEMANTICS_FIELDS=1 bundle exec rake templates -``` - -Compile to WASM using WASI SDK version 25: - -``` -make java-wasm WASI_SDK_PATH=.../wasi-sdk-25.0-arm64-macos -``` - -Build the AOT-compiled machine and wrapper library: - -``` -mvn -f java-wasm/pom.xml clean package -``` - -This should build the chicory-wasm jar file and pass some basic tests. - -The jar will be under `java-wasm/target/chicory-prism-#####-SNAPSHOT.jar` or can be installed by using `install` instead of `pacakge` in the `mvn` command line above. - -## Releasing - -Pass `-Prelease` to enable release plugins for Maven Central (optional for snapshots) and run the `deploy` target for `mvn`. diff --git a/java-wasm/pom.xml b/java-wasm/pom.xml deleted file mode 100644 index 49aae5b3f1..0000000000 --- a/java-wasm/pom.xml +++ /dev/null @@ -1,236 +0,0 @@ - - - 4.0.0 - - org.ruby-lang - prism-parser - 0.0.2-SNAPSHOT - Java Prism - Java API for the Prism Ruby language parser - https://github.com/ruby/prism - - - - MIT - - - - - - Kevin Newton - kddnewton@gmail.com - - - Benoit Daloze - eregontp@gmail.com - - - Charles Oliver Nutter - headius@headius.com - - - Thomas E Enebo - tom.enebo@gmail.com - - - - - https://github.com/ruby/prism - https://github.com/ruby/prism.git - - - - UTF-8 - UTF-8 - 21 - 21 - - 1.7.3 - 6.0.3 - - - - - - com.dylibso.chicory - bom - ${chicory.version} - pom - import - - - - - - - com.dylibso.chicory - runtime - - - com.dylibso.chicory - log - - - com.dylibso.chicory - wasi - - - com.dylibso.chicory - wasm - - - org.junit.jupiter - junit-jupiter-engine - ${junit.version} - test - - - com.dylibso.chicory - annotations - provided - - - org.jruby - jruby-complete - 10.0.4.0 - test - - - - - - release - - - - maven-source-plugin - - - attach-sources - - jar-no-fork - - - - - - maven-javadoc-plugin - - - attach-javadocs - - jar - - - - - none - - - - maven-gpg-plugin - 3.2.8 - - - sign-artifacts - verify - - sign - - - - - - --pinentry-mode - loopback - - - - - - - - - - - - org.codehaus.mojo - templating-maven-plugin - 3.1.0 - - - filtering-java-templates - - filter-sources - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.15.0 - - 21 - - - com.dylibso.chicory - annotations-processor - ${chicory.version} - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.5.5 - - - org.codehaus.mojo - build-helper-maven-plugin - 3.6.1 - - - generate-sources - - add-source - - - - ../java - - - - - - - com.dylibso.chicory - chicory-compiler-maven-plugin - ${chicory.version} - - - prism - - compile - - - org.ruby_lang.prism.wasm.PrismParser - src/test/resources/prism.wasm - - - - - - org.sonatype.central - central-publishing-maven-plugin - 0.10.0 - true - - central - - - - - - diff --git a/java/.gitignore b/java/.gitignore new file mode 100644 index 0000000000..a88111250b --- /dev/null +++ b/java/.gitignore @@ -0,0 +1,4 @@ +api/target +native/target +wasm/target +.idea diff --git a/java/README.md b/java/README.md new file mode 100644 index 0000000000..6380850e00 --- /dev/null +++ b/java/README.md @@ -0,0 +1,62 @@ +# Prism Java API and bindings + +This is the top-level project for the Java API and backend bindings for the Prism Ruby language parser. + +* api/ contains the API +* native/ contains a native binding for the Prism shared library +* wasm/ contains a Chicory-based WASM build and binding + +## Building the Java components + +Some files need to be generated before the Maven artifacts can build: + +### Templated sources + +Sources under `api` are generated from templates in `../templates`. Those sources are generated using the follow command line: + +``` +$ PRISM_EXCLUDE_PRETTYPRINT=1 PRISM_SERIALIZE_ONLY_SEMANTICS_FIELDS=1 bundle exec rake templates +``` + +The files go under `api/target/generated-sources/java` and will be removed with `mvn clean`. + +### WASM build of Prism + +The `wasm` project needs a WASM build of Prism to be generated with the following command: + +``` +$ make java-wasm WASI_SDK_PATH= +``` + +The files go under `wasm/target/generated-sources/wasm` and will be removed with `mvn clean`. + +### Build and install + +The projects can be built and installed into a local Maven repository by running the following command: + +``` +$ mvn install +``` + +## Updating versions + +Run the following command to update all module versions: + +``` +$ mvn versions:set -DnewVersion=1.2.3-SNAPSHOT +``` + +## Releasing + +Snapshots can be deployed to the Maven snapshot repository while the versions end with `-SNAPSHOT`: + +``` +$ mvn deploy +``` + +When releasing to Maven Central, all projects should be released together using the `release` profile, which will use the local default GPG key to sign the packages: + +``` +$ mvn deploy -Prelease +``` + diff --git a/java/api/pom.xml b/java/api/pom.xml new file mode 100644 index 0000000000..043173366c --- /dev/null +++ b/java/api/pom.xml @@ -0,0 +1,39 @@ + + + 4.0.0 + + + org.ruby-lang + prism-parser + 0.0.2-SNAPSHOT + + + prism-parser-api + Java Prism + Java API for the Prism Ruby language parser + https://github.com/ruby/prism + + + + + org.codehaus.mojo + build-helper-maven-plugin + 3.6.1 + + + generate-sources + + add-source + + + + target/generated-sources/java + + + + + + + + + diff --git a/java/org/ruby_lang/prism/MarkNewlinesVisitor.java b/java/api/src/main/java/org/ruby_lang/prism/MarkNewlinesVisitor.java similarity index 100% rename from java/org/ruby_lang/prism/MarkNewlinesVisitor.java rename to java/api/src/main/java/org/ruby_lang/prism/MarkNewlinesVisitor.java diff --git a/java/org/ruby_lang/prism/ParseResult.java b/java/api/src/main/java/org/ruby_lang/prism/ParseResult.java similarity index 100% rename from java/org/ruby_lang/prism/ParseResult.java rename to java/api/src/main/java/org/ruby_lang/prism/ParseResult.java diff --git a/java/org/ruby_lang/prism/ParsingOptions.java b/java/api/src/main/java/org/ruby_lang/prism/ParsingOptions.java similarity index 100% rename from java/org/ruby_lang/prism/ParsingOptions.java rename to java/api/src/main/java/org/ruby_lang/prism/ParsingOptions.java diff --git a/java/native/pom.xml b/java/native/pom.xml new file mode 100644 index 0000000000..06f866858c --- /dev/null +++ b/java/native/pom.xml @@ -0,0 +1,16 @@ + + + 4.0.0 + + + org.ruby-lang + prism-parser + 0.0.2-SNAPSHOT + + + prism-parser-native + Java Prism Native + Java native bindings Prism parser shared library + https://github.com/ruby/prism + + diff --git a/java/org/ruby_lang/prism/Parser.java b/java/native/src/main/java/org/ruby_lang/prism/Parser.java similarity index 100% rename from java/org/ruby_lang/prism/Parser.java rename to java/native/src/main/java/org/ruby_lang/prism/Parser.java diff --git a/java/pom.xml b/java/pom.xml new file mode 100644 index 0000000000..1085477010 --- /dev/null +++ b/java/pom.xml @@ -0,0 +1,139 @@ + + + 4.0.0 + + org.ruby-lang + prism-parser + 0.0.2-SNAPSHOT + pom + Java Prism + Java API for the Prism Ruby language parser + https://github.com/ruby/prism + + + + MIT + + + + + + Kevin Newton + kddnewton@gmail.com + + + Benoit Daloze + eregontp@gmail.com + + + Charles Oliver Nutter + headius@headius.com + + + Thomas E Enebo + tom.enebo@gmail.com + + + + + https://github.com/ruby/prism + https://github.com/ruby/prism.git + + + + UTF-8 + UTF-8 + 21 + 21 + 6.0.3 + + + + api + native + wasm + + + + + release + + + + maven-gpg-plugin + 3.2.4 + + + sign-artifacts + verify + + sign + + + + + + --pinentry-mode + loopback + + + + + + + + + + + + maven-compiler-plugin + 3.15.0 + + 21 + + + + maven-source-plugin + 3.4.0 + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.5.5 + + + maven-javadoc-plugin + 3.12.0 + + + attach-javadocs + + jar + + + + + none + + + + org.sonatype.central + central-publishing-maven-plugin + 0.7.0 + true + + central + + + + + + diff --git a/java-wasm/.gitignore b/java/wasm/.gitignore similarity index 100% rename from java-wasm/.gitignore rename to java/wasm/.gitignore diff --git a/java-wasm/perf-test/.gitignore b/java/wasm/perf-test/.gitignore similarity index 100% rename from java-wasm/perf-test/.gitignore rename to java/wasm/perf-test/.gitignore diff --git a/java-wasm/perf-test/bench.sh b/java/wasm/perf-test/bench.sh similarity index 100% rename from java-wasm/perf-test/bench.sh rename to java/wasm/perf-test/bench.sh diff --git a/java-wasm/perf-test/test b/java/wasm/perf-test/test similarity index 100% rename from java-wasm/perf-test/test rename to java/wasm/perf-test/test diff --git a/java/wasm/pom.xml b/java/wasm/pom.xml new file mode 100644 index 0000000000..d652780606 --- /dev/null +++ b/java/wasm/pom.xml @@ -0,0 +1,126 @@ + + + 4.0.0 + + + org.ruby-lang + prism-parser + 0.0.2-SNAPSHOT + + + prism-parser-wasm + Java Prism WASM + Java WASM bindings for the Prism parser shared library + https://github.com/ruby/prism + + + 1.7.3 + + + + + + com.dylibso.chicory + bom + ${chicory.version} + pom + import + + + + + + + org.ruby-lang + prism-parser-api + 0.0.2-SNAPSHOT + + + com.dylibso.chicory + runtime + + + com.dylibso.chicory + log + + + com.dylibso.chicory + wasi + + + com.dylibso.chicory + wasm + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + + com.dylibso.chicory + annotations + provided + + + org.jruby + jruby-complete + 10.0.4.0 + test + + + + + + + org.codehaus.mojo + templating-maven-plugin + 3.1.0 + + + filtering-java-templates + + filter-sources + + + + + + maven-compiler-plugin + + 21 + + + com.dylibso.chicory + annotations-processor + ${chicory.version} + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.5.5 + + + com.dylibso.chicory + chicory-compiler-maven-plugin + ${chicory.version} + + + prism + + compile + + + org.ruby_lang.prism.wasm.PrismParser + src/test/resources/prism.wasm + + + + + + + + diff --git a/java/wasm/prism-parser.iml b/java/wasm/prism-parser.iml new file mode 100644 index 0000000000..99039ba2ed --- /dev/null +++ b/java/wasm/prism-parser.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/java-wasm/src/main/java-templates/org/ruby_lang/prism/wasm/WasmResource.java b/java/wasm/src/main/java-templates/org/ruby_lang/prism/wasm/WasmResource.java similarity index 100% rename from java-wasm/src/main/java-templates/org/ruby_lang/prism/wasm/WasmResource.java rename to java/wasm/src/main/java-templates/org/ruby_lang/prism/wasm/WasmResource.java diff --git a/java-wasm/src/main/java/org/ruby_lang/prism/wasm/Prism.java b/java/wasm/src/main/java/org/ruby_lang/prism/wasm/Prism.java similarity index 100% rename from java-wasm/src/main/java/org/ruby_lang/prism/wasm/Prism.java rename to java/wasm/src/main/java/org/ruby_lang/prism/wasm/Prism.java diff --git a/java-wasm/src/test/java/org/jruby/parser/prism/JRubyTest.java b/java/wasm/src/test/java/org/jruby/parser/prism/JRubyTest.java similarity index 100% rename from java-wasm/src/test/java/org/jruby/parser/prism/JRubyTest.java rename to java/wasm/src/test/java/org/jruby/parser/prism/JRubyTest.java diff --git a/java-wasm/src/test/java/org/jruby/parser/prism/WASMTest.java b/java/wasm/src/test/java/org/jruby/parser/prism/WASMTest.java similarity index 100% rename from java-wasm/src/test/java/org/jruby/parser/prism/WASMTest.java rename to java/wasm/src/test/java/org/jruby/parser/prism/WASMTest.java diff --git a/java-wasm/src/test/resources/.gitignore b/java/wasm/src/test/resources/.gitignore similarity index 100% rename from java-wasm/src/test/resources/.gitignore rename to java/wasm/src/test/resources/.gitignore diff --git a/rakelib/check_manifest.rake b/rakelib/check_manifest.rake index 2c8fced816..ff88543fa9 100644 --- a/rakelib/check_manifest.rake +++ b/rakelib/check_manifest.rake @@ -19,7 +19,7 @@ task check_manifest: :templates do gemfiles javascript java - java-wasm + java/wasm pkg rakelib rust diff --git a/templates/java/org/ruby_lang/prism/AbstractNodeVisitor.java.erb b/templates/java/api/target/generated-sources/java/org/ruby_lang/prism/AbstractNodeVisitor.java.erb similarity index 100% rename from templates/java/org/ruby_lang/prism/AbstractNodeVisitor.java.erb rename to templates/java/api/target/generated-sources/java/org/ruby_lang/prism/AbstractNodeVisitor.java.erb diff --git a/templates/java/org/ruby_lang/prism/Loader.java.erb b/templates/java/api/target/generated-sources/java/org/ruby_lang/prism/Loader.java.erb similarity index 100% rename from templates/java/org/ruby_lang/prism/Loader.java.erb rename to templates/java/api/target/generated-sources/java/org/ruby_lang/prism/Loader.java.erb diff --git a/templates/java/org/ruby_lang/prism/Nodes.java.erb b/templates/java/api/target/generated-sources/java/org/ruby_lang/prism/Nodes.java.erb similarity index 100% rename from templates/java/org/ruby_lang/prism/Nodes.java.erb rename to templates/java/api/target/generated-sources/java/org/ruby_lang/prism/Nodes.java.erb diff --git a/templates/template.rb b/templates/template.rb index 5d1afc9506..9ab3ab4048 100755 --- a/templates/template.rb +++ b/templates/template.rb @@ -688,9 +688,9 @@ def locals "javascript/src/deserialize.js", "javascript/src/nodes.js", "javascript/src/visitor.js", - "java/org/ruby_lang/prism/Loader.java", - "java/org/ruby_lang/prism/Nodes.java", - "java/org/ruby_lang/prism/AbstractNodeVisitor.java", + "java/api/target/generated-sources/java/org/ruby_lang/prism/Loader.java", + "java/api/target/generated-sources/java/org/ruby_lang/prism/Nodes.java", + "java/api/target/generated-sources/java/org/ruby_lang/prism/AbstractNodeVisitor.java", "lib/prism/compiler.rb", "lib/prism/dispatcher.rb", "lib/prism/dot_visitor.rb",