Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sample of shared library #152

Open
jperedadnr opened this issue Jul 20, 2022 · 3 comments
Open

Add sample of shared library #152

jperedadnr opened this issue Jul 20, 2022 · 3 comments

Comments

@jperedadnr
Copy link
Contributor

After gluonhq/substrate#1157, provide a sample that creates a shared library.

@shafqatevo
Copy link

shafqatevo commented Oct 4, 2022

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.

@kosyloa
Copy link

kosyloa commented Jan 19, 2023

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?

@ennerf
Copy link
Contributor

ennerf commented Oct 19, 2023

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants