Running on Apple M1

I saw that there had been no movement on this issue (Feature request: Support MacOS ARM · Issue #261 · openrndr/openrndr · GitHub)about M1 support, but it looked like, since there does exist a LWJGL version that supports the M1, this could be an easy change to do my self. However, I was looking at the template project, and I am new to the Gradle build system and couldn’t find where the dependencies are listed. Is there an easy way to locally bump the LWJGL version to get OPENRNDR to run on an M1 mac?

Hi hi ! Welcome to the forum :slight_smile:

Have you tried with the 0.4 branch?

To try you can do this:

#  build latest openrndr and publish to local maven
git clone https://github.com/openrndr/openrndr
cd openrndr
./gradlew publishToMavenLocal -Prelease.version=0.5.1-SNAPSHOT
cd ..

#  build latest orx and publish to local maven
git clone https://github.com/openrndr/orx
cd orx
./gradlew publishToMavenLocal -Prelease.version=0.5.1-SNAPSHOT
cd ..

# clone 0.4 branchn of the template, which uses local maven snapshots by default
git clone https://github.com/openrndr/openrndr-template.git
cd openrndr-template
git checkout openrndr-0.4

Thanks for the tip! Unfortunately this is the output I get from trying to build openrnder

> Configure project :openrndr-animatable
Kotlin Multiplatform Projects are an Alpha feature. See: https://kotlinlang.org/docs/reference/evolution/components-stability.html. To hide this message, add 'kotlin.mpp.stability.nowarn=true' to the Gradle properties.


FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':kotlinNodeJsSetup'.
> Could not resolve all files for configuration ':detachedConfiguration4'.
   > Could not find org.nodejs:node:14.17.0.
     Searched in the following locations:
       - https://repo.maven.apache.org/maven2/org/nodejs/node/14.17.0/node-14.17.0.pom
       - https://nodejs.org/dist/v14.17.0/node-v14.17.0-darwin-arm64.tar.gz
     Required by:
         project :

I have node 14.17.0 installed on my system through nvm

it seems related to this issue in Kotlin Multiplatform, but again, I’m not sure how to go in and change the relevant configurations to update the reference to the node.js version - https://youtrack.jetbrains.com/issue/KT-49109

Good find. I asked in Slack.

So until Kotlin 1.6.20 is released, a workaround seems to be adding

rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin> {
    rootProject.the<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension>().nodeVersion = "16.0.0"
}

into settings.gradle in openrndr. The issue is that the code above is written in Kotlin (kts) syntax, but openrndr so far uses Groovy. Do you know how to write the above in Groovy?

I can give it a try but unfortunately i’m not exactly sure what this code means syntactically in kotlin either (it’s my first time picking up both kotlin and gradle). I found this Migrating build logic from Groovy to Kotlin to help, but nothing yet to assist specifically in the kotlin => groovy direction

Maybe this Chinese website shows how to do it?

// settings.gradle in openrndr
rootProject.plugins.withType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin) {
    rootProject.extensions.getByType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension).nodeVersion = "16.0.0"
}

Update: in the YouTrack link above they suggested this alternative:

rootProject.plugins.withType(Class.forName("org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin")) {
    rootProject.extensions.getByType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension.class).nodeVersion = "16.0.0"
}

Unfortunately that results in the following error:

FAILURE: Build failed with an exception.

* Where:
Settings file '/Users/avneeshsarwate/openrndr/settings.gradle' line: 42

* What went wrong:
A problem occurred evaluating settings 'openrndr'.
> No such property: plugins for class: org.gradle.initialization.DefaultProjectDescriptor

(I think i might just wait for Kotlin 1.6.20 to be release, which i think will have a built in update to the node.js version, just leaving the current state of things in case it’s helpful to anyone else)

If you’re not bored of trying yet… :slight_smile: how does your settings.gradle file look like? Something like this?

rootProject.name = 'openrndr'

rootProject.plugins.withType(Class.forName("org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin")) {
    rootProject.extensions.getByType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension.class).nodeVersion = "16.0.0"
}

include 'openrndr-application',
        'openrndr-core',
        'openrndr-demos',
        'openrndr-draw',
        'openrndr-math',
        'openrndr-color',
        'openrndr-shape',
        'openrndr-event',
        'openrndr-binpack',
        'openrndr-filter',
        'openrndr-svg',
        'openrndr-animatable',
        'openrndr-jvm:openrndr-dialogs',
        'openrndr-jvm:openrndr-ffmpeg',
        'openrndr-jvm:openrndr-ffmpeg-natives-windows',
        'openrndr-jvm:openrndr-ffmpeg-natives-macos',
        'openrndr-jvm:openrndr-ffmpeg-natives-linux-x64',
        'openrndr-jvm:openrndr-ffmpeg-natives-linux-arm64',
        'openrndr-jvm:openrndr-gl3',
        'openrndr-jvm:openrndr-gl3-natives-linux-x64',
        'openrndr-jvm:openrndr-gl3-natives-linux-arm64',
        'openrndr-jvm:openrndr-gl3-natives-macos',
        'openrndr-jvm:openrndr-gl3-natives-macos-arm64',
        'openrndr-jvm:openrndr-gl3-natives-windows',
        'openrndr-jvm:openrndr-openal',
        'openrndr-jvm:openrndr-openal-natives-linux-x64',
        'openrndr-jvm:openrndr-openal-natives-linux-arm64',
        'openrndr-jvm:openrndr-openal-natives-macos',
        'openrndr-jvm:openrndr-openal-natives-macos-arm64',
        'openrndr-jvm:openrndr-openal-natives-windows',
        'openrndr-jvm:openrndr-tessellation',
        'openrndr-js:openrndr-webgl',
        'openrndr-extensions',
        'openrndr-nullgl',
        'openrndr-utils',
        'openrndr-dds',
        'openrndr-kartifex',
        'openrndr-ktessellation'

Yup - initially had the plugins line at the end, and tried with the plugins statement after the first line, same issue

Ok, at least we tried :slight_smile: If someone mentions other tricks in Slack I’ll share them here. I think another user did use M1 somehow…

I appreciate all the help!

I managed to make it work !

A bit complicated but here are the steps :

First, following Abe’s comment clone the openrndr and orx projects.


In the openrndr project

rootProject.plugins.withType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin) {
	rootProject.kotlinNodeJs.nodeVersion = "16.0.0"
}
  • build it locally : ./gradlew -Prelease.version=0.5.1-SNAPSHOT publishToMavenLocal

In the orx project

  • in the build.gradle set node version
rootProject.plugins.withType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin) {
    rootProject.kotlinNodeJs.nodeVersion = "16.0.0"
}
  • Make sure openrndrVersion is set to 0.5.1-SNAPSHOT and then build it like : ./gradlew -Prelease.version=0.5.1-SNAPSHOT publishToMavenLocal

In the openrndr-template on the master branch:

  • change the openrndrVersion, orxVersion and ormlVersion to the 0.5.1-SNAPSHOT
  • add maven(url="https://oss.sonatype.org/content/repositories/snapshots/") in repositories.
  • On the command line run ./gradlew build and then ./gradlew run or use the main function’s green arrow and it works!

Hope this helps

1 Like

Amazing! this did it! a couple notes:

For those reading later, for the openrndr-template changes, the maven repository needs to be done in settings.gradle.kts.

Also in that file, i had to set openrndrUseSnapshot = true and orxUseSnapshot = true - otherwise, the openrndr-template project would build, but the TemplateProgram would not run.

Thank you so much for the help!

2 Likes

Very nice that you made it work! I find it a bit odd to change lwjglVersion because master is already using 3.3.0, and 3.3.0-SNAPSHOT was needed before 3.3.0 was released. Could you try keeping it at

lwjglVersion = '3.3.0'

and not adding

maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }

? Maybe it works still? Just wondering what’s the minimum change required… :slight_smile:

Yep it works well with keeping lwjglVersion at 3.3.0 and staying with mavenCentral.

But now the issue I have is when trying to use the camera this error is thrown :

no jniavutil in java.library.path /Users/faw/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:

It seems org.bytedeco haven’t released a Mac m1 version of ffmpeg yet…

That sounds more tricky to solve… Either waiting or building your own ffmpeg? No idea where to start with that…

Going back to the steps required to make it work: I wonder if the other two changes from https://github.com/openrndr/openrndr/compare/master...ink404:m1-support are required? because they are changing the plain macos version, not the macos-arm64… Could it be that the only thing needed was updating the nodejs version in two files? If that’s the case then we can post a solution (either here or updating the actual source, so it just works… except ffmpeg for now).

Those changes seem needed, if I leave native-macos instead of changing it to native-macos-arm64, running the simple template throws:

[LWJGL] Platform/architecture mismatch detected for module: org.lwjgl
        JVM platform:
                macOS aarch64 17.0.2
                OpenJDK 64-Bit Server VM v17.0.2+8-86 by Oracle Corporation
        Platform available on classpath:
                macos/x64
[LWJGL] Failed to load a library. Possible solutions:
        a) Add the directory that contains the shared library to -Djava.library.path or -Dorg.lwjgl.librarypath.
        b) Add the JAR that contains the shared library to the classpath.

For ffmpeg in some articles they talk about adding ffmpeg-platform as dependency. I also saw that org.bytedeco.javacpp:1.5.6 starts introducing jars for macOS-arm64. I’ll give it a try later.

1 Like

Managed to make the camera work!
To do so I needed to install ffmpeg on my Mac.

brew install ffmpeg

Then I had to bump ffmpeg in openrndr’s build.gradle to use the 5.0-1.5.7.

line 50-51:

    javacpp_version = '1.5.7'
    ffmpeg_version = "5.0-$javacpp_version"

Then change openrndr-jvm/openrndr-ffmpeg-natives-macos/build.gradle to use the arm64 version of the jars.

dependencies {
    runtimeOnly "org.bytedeco:ffmpeg:$ffmpeg_version:macosx-arm64"
    runtimeOnly "org.bytedeco:javacpp:$javacpp_version:macosx-arm64"
}

Due to moving to version 5.0, in openrndr-jvm/openrndr-ffmpeg/src/main/kotlin/org/openrndr/ffmpeg some functions used In AudioDecoder.kt and VideoDecoder.kt became deprecated and needs to be changed.
I didn’t actually try the audio functionalities, so I’m not sure the following changes are good, but at least it compiles :
AudioDecoder.kt:123 :

// Replace the following line
//            val size = avcodec_decode_audio4(audioCodecContext, audioFrame, frameFinished, packet)
// With the next one
var ret = avcodec.avcodec_send_packet(audioCodecContext, packet)

AudioDecoder.kt:183 :

// Change
// val buffer = av_buffer_alloc(audioFrameSize)!!
// To
val buffer = av_buffer_alloc(audioFrameSize.toLong())!!

VideoDecoder.kt:141

// Change
// val buffer = av_buffer_alloc(scaledFrameSize)!!
// To
val buffer = av_buffer_alloc(scaledFrameSize.toLong()())!!

Recompile the whole thing and it should work!

Also make make sure you run the program through IntelliJ and not command line. If you run gradle through command line the Mac is not going to ask for the camera permissions and if it doesn’t have this permission it will crash.

1 Like