Skip to content

Commit

Permalink
W-11098171: Build windows (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlischetti authored May 9, 2022
1 parent c2aa771 commit af829d1
Show file tree
Hide file tree
Showing 16 changed files with 273 additions and 162 deletions.
75 changes: 36 additions & 39 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,52 +17,49 @@ jobs:
OSX_LINUX_WINDOWS:
strategy:
matrix:
# os: [macos-latest, ubuntu-latest, windows-2019]
os: [macos-latest, ubuntu-latest]
os: [macos-latest, ubuntu-latest, windows-latest]
include:
# - os: windows-2019
# script_name: windows
- os: windows-latest
script_name: windows
- os: ubuntu-latest
script_name: linux
- os: macos-latest
script_name: osx
runs-on: ${{ matrix.os }}

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11

# Runs a single command using the runners shell
- name: Run Build on native
run: ./gradlew --stacktrace native-cli:build
shell: bash
env:
AWS_ACCESS_KEY_ID: ${{secrets.AWS_ACCESS_KEY_ID}}
AWS_SECRET_KEY: ${{secrets.AWS_SECRET_KEY}}
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

# Read graalvm version
- name: Read Graalvm version
run: |
echo "GRAALVM_VERSION=$(grep graalvmVersion gradle.properties | cut -d '=' -f2)" >> $GITHUB_ENV
shell: bash

# Setup Graalvm
- name: Setup Graalvm
uses: graalvm/setup-graalvm@v1
with:
version: ${{env.GRAALVM_VERSION}}
java-version: '11'
components: 'native-image'
github-token: ${{ secrets.GITHUB_TOKEN }}

# Runs a set of commands using the runners shell
- name: Create Native Image
run: ./gradlew --stacktrace --debug native-cli:nativeImage
shell: bash
env:
AWS_ACCESS_KEY_ID: ${{secrets.AWS_ACCESS_KEY_ID}}
AWS_SECRET_KEY: ${{secrets.AWS_SECRET_KEY}}
- name: Generate Distro
run: |
./gradlew --stacktrace native-cli:distro
env:
AWS_ACCESS_KEY_ID: ${{secrets.AWS_ACCESS_KEY_ID}}
AWS_SECRET_KEY: ${{secrets.AWS_SECRET_KEY}}
# Runs a single command using the runners shell
- name: Run Build
run: |
./gradlew --stacktrace build
shell: bash

# Generate distro
- name: Create Distro
run: ./gradlew --stacktrace native-cli:distro
shell: bash

# Upload the generated artifact
- name: Upload generated script
uses: actions/upload-artifact@v2
with:
name: dw-${{env.NATIVE_VERSION}}-${{runner.os}}
path: native-cli/build/distributions/native-cli-${{env.NATIVE_VERSION}}-native-distro-${{ matrix.script_name }}.zip
# This workflow contains a single job called "build"
# Upload the artifact file
- name: Upload generated script
uses: actions/upload-artifact@v2
with:
name: dw-${{env.NATIVE_VERSION}}-${{runner.os}}
path: native-cli/build/distributions/native-cli-${{env.NATIVE_VERSION}}-native-distro-${{ matrix.script_name }}.zip
39 changes: 23 additions & 16 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ jobs:
RELEASE_EXTENSION:
strategy:
matrix:
# os: [macos-latest, ubuntu-latest, windows-latest]
os: [macos-latest, ubuntu-latest]
os: [macos-latest, ubuntu-latest, windows-latest]
include:
# - os: windows-2019
# script_name: windows
- os: windows-latest
script_name: windows
- os: ubuntu-latest
script_name: linux
- os: macos-latest
Expand All @@ -27,25 +26,33 @@ jobs:
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1

# Read graalvm version
- name: Read Graalvm version
run: |
echo "GRAALVM_VERSION=$(grep graalvmVersion gradle.properties | cut -d '=' -f2)" >> $GITHUB_ENV
shell: bash

# Setup Graalvm
- name: Setup Graalvm
uses: graalvm/setup-graalvm@v1
with:
java-version: 11
version: ${{env.GRAALVM_VERSION}}
java-version: '11'
components: 'native-image'
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Guess Extension Version
run: |
echo "NATIVE_VERSION=$(echo '${{github.ref}}' | sed -e 's,.*/v\(.*\),\1,')" >> $GITHUB_ENV
# Runs a single command using the runners shell
- name: Run Build on native
run: ./gradlew native-cli:build -PnativeVersion=${{env.NATIVE_VERSION}}
shell: bash

# Runs a set of commands using the runners shell
- name: Create Native Image
run: ./gradlew native-cli:nativeImage -PnativeVersion=${{env.NATIVE_VERSION}}
- name: Run Build
run: |
./gradlew build -PnativeVersion=${{env.NATIVE_VERSION}}
shell: bash


# Generate distro
- name: Create Distro
run: ./gradlew native-cli:distro -PnativeVersion=${{env.NATIVE_VERSION}}
shell: bash
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ out/
*.idea

# Mac
.DS_Store
.DS_Store

# GraalVM
.graalvm
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,27 @@ brew install dw
```

### Manual Installation
1. Download the zip
1. [Mac](https://github.com/mulesoft-labs/data-weave-cli/releases/download/v1.0.16/dw-1.0.16-macOS)
2. [Linux](https://github.com/mulesoft-labs/data-weave-cli/releases/download/v1.0.16/dw-1.0.16-Linux)
3. [Windows](https://github.com/mulesoft-labs/data-weave-native/releases/download/v1.0.9/dw-1.0.9-Windows.zip) Very OLD :(!
1. Download the latest [release version](https://github.com/mulesoft-labs/data-weave-cli/releases) according to your OS.
2. Unzip the file on your `<user.home>/.dw`
3. Add `<user.home>/.dw/bin` to your **PATH**

### Build and Install
Execute the gradle task `nativeImage`

To build the project, you need to run gradlew with the graalVM distribution based on Java 11. You can download it at https://github.com/graalvm/graalvm-ce-builds/releases
Set:
```bash
./gradlew native-cli:nativeImage
export GRAALVM_HOME=<pathToGraalVMFolder>/graalvm-ce-java11-21.2.0/Contents/Home
export JAVA_HOME=<pathToGraalVMFolder>/graalvm-ce-java11-21.2.0/Contents/Home
```
Execute the gradle task `nativeCompile`

```bash
./gradlew native-cli:nativeCompile
```

It takes several minutes so good time to take and refill your mate.

Once it finishes you will find the `dw` binary in `native-cli/build/graal/dw`
Once it finishes you will find the `dw` binary in `native-cli/build/native/nativeCompile/dw`

## How to Use It

Expand Down
8 changes: 1 addition & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,12 @@ buildscript {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.com.palantir.graal:gradle-graal:0.7.2"
}
}


apply plugin: 'com.palantir.graal'

subprojects {

apply plugin: "java"
apply plugin: "scala"
apply plugin: 'com.palantir.graal'
apply plugin: 'maven-publish'

group 'org.mule.weave.native'
Expand Down Expand Up @@ -73,6 +66,7 @@ subprojects {
name "jitpack.io"
url "https://jitpack.io"
}
gradlePluginPortal()
}


Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip
34 changes: 34 additions & 0 deletions install-graalvm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

source gradle.properties

graal_dir=.graalvm

[[ $(uname -a) =~ Darwin ]] && os=darwin || os=linux

setUpEnvironmentVariables() {
echo "Setup GRAALVM_HOME and JAVA_HOME environment variables"
if [[ $os == darwin ]]
then
export GRAALVM_HOME=${PWD}/${graal_dir}/graalvm-ce-java11-${graalvmVersion}/Contents/Home
else
export GRAALVM_HOME=${PWD}/${graal_dir}/graalvm-ce-java11-${graalvmVersion}
fi
export JAVA_HOME=${GRAALVM_HOME}
}

if [[ ! -d ${graal_dir}/graalvm-ce-java11-${graalvmVersion} ]]
then
graalvmDist=graalvm-ce-java11-${os}-amd64-${graalvmVersion}.tar.gz
echo "Installing GraalVM: ${graalvmDist}"
mkdir -p ${graal_dir}
pushd ${graal_dir}
curl -OL -A "Mozilla Chrome Safari" https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-${graalvmVersion}/${graalvmDist}
tar xf ${graalvmDist}
echo $graal_dir
popd
setUpEnvironmentVariables
${GRAALVM_HOME}/bin/gu install native-image
else
echo "GraalVM already installed"
fi
2 changes: 1 addition & 1 deletion native-cli-integration-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ dependencies {
testRuntime 'org.pegdown:pegdown:1.6.0'
}

test.dependsOn(":native-cli:nativeImage")
test.dependsOn(":native-cli:nativeCompile")
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@ import java.io.File
import java.util.concurrent.TimeUnit
import scala.io.Source

class NativeCliITTestRunner(args: Array[String]) extends ResourceResolver {
class NativeCliITTestRunner(args: Array[String])
extends ResourceResolver
with OSSupport {

private val NATIVE_CLI_INTEGRATION_TESTS = "native-cli-integration-tests"

private lazy val OS = System.getProperty("os.name").toLowerCase

private lazy val EXECUTABLE_NAME = {
if (OS.contains("win")) {
if (isWindows) {
"dw.exe"
} else {
"dw"
}
}

private lazy val DW_CLI_EXECUTABLE: String = {
val path = getResourcePath(getClass.getName.replaceAll("\\.", File.separator) + ".class")
val path = getResourcePath(getClass.getName.replace(".", File.separator) + ".class")
var nativeCliIntegrationTest = new File(path)
while (nativeCliIntegrationTest.getName != NATIVE_CLI_INTEGRATION_TESTS) {
nativeCliIntegrationTest = nativeCliIntegrationTest.getParentFile
}
val dwPath = new File(nativeCliIntegrationTest.getParentFile, s"native-cli/build/graal/$EXECUTABLE_NAME")
val dwPath = new File(nativeCliIntegrationTest.getParentFile, s"native-cli/build/native/nativeCompile/$EXECUTABLE_NAME")
dwPath.getAbsolutePath
}

Expand Down
Loading

0 comments on commit af829d1

Please sign in to comment.