<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>io.roastedroot</groupId>
    <artifactId>chicory-redline-parent</artifactId>
    <version>0.0.5</version>
    <relativePath>../pom.xml</relativePath>
  </parent>
  <artifactId>redline-bridge</artifactId>
  <packaging>jar</packaging>

  <name>Chicory - Cranelift Bridge</name>
  <description>Java wrapper for the Cranelift code generator (compiled to Wasm)</description>

  <dependencies>
    <dependency>
      <groupId>com.dylibso.chicory</groupId>
      <artifactId>log</artifactId>
    </dependency>
    <dependency>
      <groupId>com.dylibso.chicory</groupId>
      <artifactId>runtime</artifactId>
    </dependency>
    <dependency>
      <groupId>com.dylibso.chicory</groupId>
      <artifactId>wasi</artifactId>
    </dependency>
    <dependency>
      <groupId>com.dylibso.chicory</groupId>
      <artifactId>wasm</artifactId>
    </dependency>
    <dependency>
      <groupId>com.dylibso.chicory</groupId>
      <artifactId>annotations</artifactId>
      <scope>provided</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>com.dylibso.chicory</groupId>
        <artifactId>chicory-compiler-maven-plugin</artifactId>
        <version>${chicory.version}</version>
        <executions>
          <execution>
            <id>redline</id>
            <goals>
              <goal>compile</goal>
            </goals>
            <configuration>
              <name>io.roastedroot.redline.bridge.Cranelift</name>
              <wasmFile>${project.basedir}/../cranelift_bridge.wasm</wasmFile>
              <interpreterFallback>WARN</interpreterFallback>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <id>normalize-wasm-path</id>
            <goals>
              <goal>run</goal>
            </goals>
            <phase>initialize</phase>
            <configuration>
              <target>
                <property location="${project.basedir}/../cranelift_bridge.wasm" name="wasm.resource.path.raw"/>
                <makeurl file="${wasm.resource.path.raw}" property="wasm.resource.url.temp"/>
                <loadresource property="wasm.resource.url">
                  <propertyresource name="wasm.resource.url.temp"/>
                  <filterchain>
                    <tokenfilter>
                      <replaceregex pattern="^file:/" replace="file:///"/>
                    </tokenfilter>
                  </filterchain>
                </loadresource>
              </target>
              <exportAntProperties>true</exportAntProperties>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <annotationProcessorPaths>
            <path>
              <groupId>com.dylibso.chicory</groupId>
              <artifactId>annotations-processor</artifactId>
              <version>${chicory.version}</version>
            </path>
          </annotationProcessorPaths>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>templating-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>filtering-java-templates</id>
            <goals>
              <goal>filter-sources</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
