gluon-samples icon indicating copy to clipboard operation
gluon-samples copied to clipboard

Add sample of shared library

Open jperedadnr opened this issue 3 years ago • 3 comments

After https://github.com/gluonhq/substrate/issues/1157, provide a sample that creates a shared library.

jperedadnr avatar Jul 20 '22 16:07 jperedadnr

Hi @jperedadnr is there any sample now or any guide to follow? Or would you mind providing some pointers to create shared lib for both Android and iOS?

EDIT: Just found the HelloSharedLib sample - thanks a lot!

Quick questions:

  1. Is the isolate-based approach the main way to instantiate a shared lib component?

  2. Within that Graal isolate shared lib code, can multiple additional threads be created? For example, we need to run Akka, which will need like 4 threads to schedule actors within the lib instance.

shafqatevo avatar Oct 04 '22 07:10 shafqatevo

HI @jperedadnr. I fetched your sample code. And I built shared lib for iOS Simulator. i tried run my code on simulator on m1 laptop(Arm/Silicone) And faced with few errors: First case: build shared lib for simulator. Get dylib from folder x86_64-ios and faced with error: "Ignoring file /Users//projects/TestGraalvm/TestGraalvm/HelloSharedLib.dylib, building for iOS Simulator-arm64 but attempting to link with file built for iOS Simulator-x86_64" It is expected for me. Second case: build shared lib for iOS(arm arch). Arch looks the same with real devices. But faced with another error: "building for iOS Simulator, but linking in dylib built for iOS, file '/Users//projects/TestGraalvm/TestGraalvm/HelloSharedLib.dylib' for architecture arm64"

Could you help me with correct building shared lib for simulator on M1 MacBook?

kosyloa avatar Jan 19 '23 14:01 kosyloa

@jperedadnr I tried the HelloSharedLib sample on Windows 10 and Ubuntu 20.04 (WSL2), but I can't get it to create a shared library.

Windows 10

> mvn -v

Apache Maven 3.8.7 (b89d5959fcde851dcb1c8946a785a163f14e1e29)
Maven home: C:\ProgramData\chocolatey\lib\maven\apache-maven-3.8.7
Java version: 21, vendor: Oracle Corporation, runtime: D:\toolchains\graalvm-jdk-21+35.1
Default locale: en_US, platform encoding: UTF-8
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
> mvn clean package gluonfx:sharedlib
...
[INFO] --- gluonfx-maven-plugin:1.0.21:sharedlib (default-cli) @ hellosharedlib ---
Okt. 19, 2023 5:39:06 PM com.gluonhq.substrate.util.Logger logInfo
INFO: Substrate is tested with the Gluon's GraalVM build which you can find at https://github.com/gluonhq/graal/releases.
While you can still use other GraalVM builds, there is no guarantee that these will work properly with Substrate
[Do. Okt. 19 17:39:06 MESZ 2023][INFO] ==================== SHARED LIBRARY TASK ====================
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

It "succeeds", but there is no compilation or output binaries. It works when I use GraalVM's plugin, but that fails when I use JavaFX:

<plugin>
    <groupId>org.graalvm.buildtools</groupId>
    <artifactId>native-maven-plugin</artifactId>
    <version>0.9.21</version>
    <extensions>true</extensions>
    <configuration>
        <imageName>sharedlib</imageName>
        <sharedLibrary>true</sharedLibrary>
        <useArgFile>false</useArgFile>
        <skipNativeTests>true</skipNativeTests>
        <verbose>true</verbose>
    </configuration>
</plugin>
> mvn clean package gluonfx:sharedlib
...
------------------------------------------------------------------------------------------------------------------------
                       1,2s (6,3% of total time) in 237 GCs | Peak RSS: 0,93GB | CPU load: 12,07
------------------------------------------------------------------------------------------------------------------------
Produced artifacts:
 E:\HEBI\gluon\gluon-samples\HelloSharedLib\target\graal_isolate.h (c_header)
 E:\HEBI\gluon\gluon-samples\HelloSharedLib\target\graal_isolate_dynamic.h (c_header)
 E:\HEBI\gluon\gluon-samples\HelloSharedLib\target\sharedlib.dll (shared_library)
 E:\HEBI\gluon\gluon-samples\HelloSharedLib\target\sharedlib.h (c_header)
 E:\HEBI\gluon\gluon-samples\HelloSharedLib\target\sharedlib.lib (import_library)
 E:\HEBI\gluon\gluon-samples\HelloSharedLib\target\sharedlib_dynamic.h (c_header)
========================================================================================================================
Finished generating 'sharedlib' in 18,2s.

Ubuntu 20.04

> mvn -v

Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0)
Maven home: /opt/maven
Java version: 17.0.3, vendor: GraalVM Community, runtime: /home/florian/Downloads/graalvm-svm-java17-linux-gluon-22.1.0.1-Final
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "5.15.90.1-microsoft-standard-wsl2", arch: "amd64", family: "unix"
> mvn clean package gluonfx:sharedlib

[INFO] --- gluonfx-maven-plugin:1.0.21:sharedlib (default-cli) @ hellosharedlib ---
[Thu Oct 19 17:37:44 CEST 2023][INFO] ==================== SHARED LIBRARY TASK ====================
[Thu Oct 19 17:37:47 CEST 2023][INFO] [SUB] Warning: Ignoring server-mode native-image argument --no-server.
[Thu Oct 19 17:37:49 CEST 2023][INFO] [SUB] ========================================================================================================================
[Thu Oct 19 17:37:49 CEST 2023][INFO] [SUB] GraalVM Native Image: Generating 'hello.hellosharedlib' (shared library)...
[Thu Oct 19 17:37:49 CEST 2023][INFO] [SUB] ========================================================================================================================
[Thu Oct 19 17:37:49 CEST 2023][INFO] [SUB] [GluonFeature] enabled for config com.oracle.svm.hosted.FeatureImpl$IsInConfigurationAccessImpl@7ae42ce3
[Thu Oct 19 17:37:49 CEST 2023][INFO] [SUB]
[Thu Oct 19 17:37:49 CEST 2023][INFO] [SUB] [1/7] Initializing...                                                                                    (0.0s @ 0.12GB)
[Thu Oct 19 17:37:49 CEST 2023][INFO] [SUB] Error: ImageSingletons.add must not overwrite existing key com.oracle.svm.core.jdk.ProtectionDomainSupport
[Thu Oct 19 17:37:49 CEST 2023][INFO] [SUB] Existing value: com.oracle.svm.core.jdk.ProtectionDomainSupport@6ebf0f36
[Thu Oct 19 17:37:49 CEST 2023][INFO] [SUB] New value: com.oracle.svm.core.jdk.ProtectionDomainSupport@18920cc
[Thu Oct 19 17:37:49 CEST 2023][INFO] [SUB] com.oracle.svm.core.util.UserError$UserException: ImageSingletons.add must not overwrite existing key com.oracle.svm.core.jdk.ProtectionDomainSupport
[Thu Oct 19 17:37:49 CEST 2023][INFO] [SUB] Existing value: com.oracle.svm.core.jdk.ProtectionDomainSupport@6ebf0f36
[Thu Oct 19 17:37:49 CEST 2023][INFO] [SUB] New value: com.oracle.svm.core.jdk.ProtectionDomainSupport@18920cc
[Thu Oct 19 17:37:49 CEST 2023][INFO] [SUB]     at com.oracle.svm.core.util.UserError.abort(UserError.java:72)
[Thu Oct 19 17:37:49 CEST 2023][INFO] [SUB]     at com.oracle.svm.hosted.ImageSingletonsSupportImpl$HostedManagement.doAdd(ImageSingletonsSupportImpl.java:109)
[Thu Oct 19 17:37:49 CEST 2023][INFO] [SUB]     at com.oracle.svm.hosted.ImageSingletonsSupportImpl.add(ImageSingletonsSupportImpl.java:39)
[Thu Oct 19 17:37:49 CEST 2023][INFO] [SUB]     at org.graalvm.sdk/org.graalvm.nativeimage.ImageSingletons.add(ImageSingletons.java:73)
[Thu Oct 19 17:37:49 CEST 2023][INFO] [SUB]     at com.oracle.svm.hosted.ProtectionDomainFeature.afterRegistration(ProtectionDomainFeature.java:48)
[Thu Oct 19 17:37:49 CEST 2023][INFO] [SUB]     at com.oracle.svm.hosted.NativeImageGenerator.lambda$setupNativeImage$14(NativeImageGenerator.java:832)
[Thu Oct 19 17:37:49 CEST 2023][INFO] [SUB]     at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:74)
[Thu Oct 19 17:37:49 CEST 2023][INFO] [SUB]     at com.oracle.svm.hosted.NativeImageGenerator.setupNativeImage(NativeImageGenerator.java:832)
[Thu Oct 19 17:37:49 CEST 2023][INFO] [SUB]     at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:555)
[Thu Oct 19 17:37:49 CEST 2023][INFO] [SUB]     at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:515)
[Thu Oct 19 17:37:49 CEST 2023][INFO] [SUB]     at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:407)
[Thu Oct 19 17:37:49 CEST 2023][INFO] [SUB]     at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:585)
[Thu Oct 19 17:37:49 CEST 2023][INFO] [SUB]     at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:128)
[Thu Oct 19 17:37:49 CEST 2023][INFO] [SUB]     at com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus.main(NativeImageGeneratorRunner.java:615)
[Thu Oct 19 17:37:49 CEST 2023][INFO] [SUB] ------------------------------------------------------------------------------------------------------------------------
[Thu Oct 19 17:37:49 CEST 2023][INFO] [SUB]                          0.1s (4.0% of total time) in 6 GCs | Peak RSS: 0.54GB | CPU load: 7.15
[Thu Oct 19 17:37:49 CEST 2023][INFO] [SUB] ========================================================================================================================
[Thu Oct 19 17:37:49 CEST 2023][INFO] [SUB] Failed generating 'hello.hellosharedlib' after 1.0s.
[Thu Oct 19 17:37:49 CEST 2023][INFO] [SUB] Error: Image build request failed with exit status 1
[Thu Oct 19 17:37:49 CEST 2023][SEVERE] Process compile failed with result: 1
Check the log files under /mnt/e/HEBI/gluon/gluon-samples/HelloSharedLib/target/gluonfx/x86_64-linux/gvm/log
And please check https://docs.gluonhq.com/ for more information.
[Thu Oct 19 17:37:49 CEST 2023][INFO] Logging process [compile] to file: /mnt/e/HEBI/gluon/gluon-samples/HelloSharedLib/target/gluonfx/log/process-compile-1697729869462.log
[Thu Oct 19 17:37:49 CEST 2023][SEVERE] Error building a shared image: error compiling the native image
Check the log files under /mnt/e/HEBI/gluon/gluon-samples/HelloSharedLib/target/gluonfx/x86_64-linux/gvm/log
And please check https://docs.gluonhq.com/ for more information.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

On Linux the GraalVM plugin fails with the same error.

ennerf avatar Oct 19 '23 15:10 ennerf