Skip to content

Commit 0a221a4

Browse files
authored
Merge pull request #1 from headius/wasm_integration
Formally add WASM support with Chicory
2 parents 959f954 + 7d2598f commit 0a221a4

5 files changed

Lines changed: 211 additions & 156 deletions

File tree

pom.xml

Lines changed: 58 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>org.jruby</groupId>
55
<artifactId>jruby-prism</artifactId>
66
<packaging>jar</packaging>
7-
<version>1.5.0</version>
7+
<version>2.0.0-SNAPSHOT</version>
88
<name>jruby-prism</name>
99
<description>
1010
Java portion of JRuby Prism parser support.
@@ -14,8 +14,8 @@
1414
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1515
<chicory.version>1.2.1</chicory.version>
1616
<junit.version>5.12.1</junit.version>
17-
<maven.compiler.source>17</maven.compiler.source>
18-
<maven.compiler.target>17</maven.compiler.target>
17+
<maven.compiler.source>21</maven.compiler.source>
18+
<maven.compiler.target>21</maven.compiler.target>
1919
</properties>
2020

2121
<parent>
@@ -66,12 +66,12 @@
6666
<dependency>
6767
<groupId>org.jruby</groupId>
6868
<artifactId>jruby-base</artifactId>
69-
<version>10.0.0.0-SNAPSHOT</version>
69+
<version>10.0.2.0</version>
7070
</dependency>
7171
<dependency>
72-
<groupId>com.prism</groupId>
73-
<artifactId>java-prism</artifactId>
74-
<version>999-SNAPSHOT</version>
72+
<groupId>org.jruby</groupId>
73+
<artifactId>chicory-prism</artifactId>
74+
<version>0.0.1-SNAPSHOT</version>
7575
</dependency>
7676
</dependencies>
7777

@@ -116,45 +116,6 @@
116116
</archive>
117117
</configuration>
118118
</plugin>
119-
<plugin>
120-
<groupId>org.apache.maven.plugins</groupId>
121-
<artifactId>maven-gpg-plugin</artifactId>
122-
<version>1.5</version>
123-
<executions>
124-
<execution>
125-
<id>sign-artifacts</id>
126-
<phase>verify</phase>
127-
<goals>
128-
<goal>sign</goal>
129-
</goals>
130-
</execution>
131-
</executions>
132-
</plugin>
133-
<plugin>
134-
<artifactId>maven-source-plugin</artifactId>
135-
<executions>
136-
<execution>
137-
<id>attach-sources</id>
138-
<goals>
139-
<goal>jar-no-fork</goal>
140-
</goals>
141-
</execution>
142-
</executions>
143-
</plugin>
144-
<plugin>
145-
<artifactId>maven-javadoc-plugin</artifactId>
146-
<executions>
147-
<execution>
148-
<id>attach-javadocs</id>
149-
<goals>
150-
<goal>jar</goal>
151-
</goals>
152-
</execution>
153-
</executions>
154-
<configuration>
155-
<doclint>none</doclint>
156-
</configuration>
157-
</plugin>
158119
</plugins>
159120
</build>
160121
<profiles>
@@ -210,5 +171,56 @@
210171
</plugins>
211172
</build>
212173
</profile>
174+
<profile>
175+
<id>release</id>
176+
<build>
177+
<plugins>
178+
<plugin>
179+
<artifactId>maven-gpg-plugin</artifactId>
180+
<version>1.6</version>
181+
<executions>
182+
<execution>
183+
<id>sign-artifacts</id>
184+
<phase>verify</phase>
185+
<goals>
186+
<goal>sign</goal>
187+
</goals>
188+
</execution>
189+
</executions>
190+
<configuration>
191+
<gpgArguments>
192+
<gpgArgument>--pinentry-mode</gpgArgument>
193+
<gpgArgument>loopback</gpgArgument>
194+
</gpgArguments>
195+
</configuration>
196+
</plugin>
197+
<plugin>
198+
<artifactId>maven-source-plugin</artifactId>
199+
<executions>
200+
<execution>
201+
<id>attach-sources</id>
202+
<goals>
203+
<goal>jar-no-fork</goal>
204+
</goals>
205+
</execution>
206+
</executions>
207+
</plugin>
208+
<plugin>
209+
<artifactId>maven-javadoc-plugin</artifactId>
210+
<executions>
211+
<execution>
212+
<id>attach-javadocs</id>
213+
<goals>
214+
<goal>jar</goal>
215+
</goals>
216+
</execution>
217+
</executions>
218+
<configuration>
219+
<doclint>none</doclint>
220+
</configuration>
221+
</plugin>
222+
</plugins>
223+
</build>
224+
</profile>
213225
</profiles>
214226
</project>

src/main/java/org/jruby/prism/ParserProviderPrism.java

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,43 @@
11
package org.jruby.prism;
22

3+
import jnr.ffi.LibraryLoader;
34
import org.jruby.Ruby;
45
import org.jruby.ir.builder.IRBuilderFactory;
56
import org.jruby.parser.Parser;
7+
import org.jruby.parser.ParserManager;
68
import org.jruby.parser.ParserProvider;
7-
import org.jruby.prism.parser.ParserPrism;
8-
import org.jruby.prism.parser.ParserBindingPrism;
99
import org.jruby.prism.builder.IRBuilderFactoryPrism;
10+
import org.jruby.prism.parser.ParserBindingPrism;
11+
import org.jruby.prism.parser.ParserPrismNative;
12+
import org.jruby.prism.parser.ParserPrismWasm;
1013

11-
import jnr.ffi.LibraryLoader;
14+
import java.io.File;
1215

1316
public class ParserProviderPrism implements ParserProvider {
1417
private static ParserBindingPrism prismLibrary;
1518

1619
public void initialize(String path) {
17-
if (prismLibrary != null) {
18-
System.out.println("Prism already initialized");
19-
return;
20+
if (new File(path).exists()) {
21+
if (prismLibrary != null) {
22+
System.out.println("Prism already initialized");
23+
return;
24+
}
25+
prismLibrary = LibraryLoader.create(ParserBindingPrism.class).load(path);
26+
// We do something extra here as a side-effect which is how we get an UnsatisfiedLinkError
27+
// If the library didn't in fact find the .so or has other loading problems.
28+
ParserBindingPrism.Buffer buffer = new ParserBindingPrism.Buffer(jnr.ffi.Runtime.getRuntime(prismLibrary));
29+
} else {
30+
prismLibrary = null;
2031
}
21-
prismLibrary = LibraryLoader.create(ParserBindingPrism.class).load(path);
22-
// We do something extra here as a side-effect which is how we get an UnsatisfiedLinkError
23-
// If the library didn't in fact find the .so or has other loading problems.
24-
ParserBindingPrism.Buffer buffer = new ParserBindingPrism.Buffer(jnr.ffi.Runtime.getRuntime(prismLibrary));
2532
}
2633

2734
public Parser getParser(Ruby runtime) {
28-
return new ParserPrism(runtime, prismLibrary);
35+
if (ParserManager.PARSER_WASM || prismLibrary == null) {
36+
// uninitialized dynamic lib or wasm requested
37+
return new ParserPrismWasm(runtime);
38+
}
39+
40+
return new ParserPrismNative(runtime, prismLibrary);
2941
}
3042

3143
public IRBuilderFactory getBuilderFactory() {

0 commit comments

Comments
 (0)