{"id":15687126,"url":"https://github.com/michael-simons/neo4j-java-driver-native-lib","last_synced_at":"2025-03-11T09:32:18.709Z","repository":{"id":139304527,"uuid":"304276161","full_name":"michael-simons/neo4j-java-driver-native-lib","owner":"michael-simons","description":"Example that uses GraalVM native image to create a shared library, callable from C, Ruby or other ecosystems that support foreign function interfaces.","archived":true,"fork":false,"pushed_at":"2023-03-31T14:09:46.000Z","size":75,"stargazers_count":11,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-09T03:08:03.106Z","etag":null,"topics":["graalvm","graalvm-native-image","neo4j"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/michael-simons.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-15T09:31:22.000Z","updated_at":"2025-01-15T19:31:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"80649900-a4b6-4ff5-9c92-1ca800ee203f","html_url":"https://github.com/michael-simons/neo4j-java-driver-native-lib","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michael-simons%2Fneo4j-java-driver-native-lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michael-simons%2Fneo4j-java-driver-native-lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michael-simons%2Fneo4j-java-driver-native-lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michael-simons%2Fneo4j-java-driver-native-lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/michael-simons","download_url":"https://codeload.github.com/michael-simons/neo4j-java-driver-native-lib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243007302,"owners_count":20220806,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graalvm","graalvm-native-image","neo4j"],"created_at":"2024-10-03T17:43:52.330Z","updated_at":"2025-03-11T09:32:18.697Z","avatar_url":"https://github.com/michael-simons.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Build and run\n\nThis shows how to use GraalVM native image to create a shared library from a Java program.\nTo define an entry point for a native library inside your Java program, you will need the following artifact in your build:\n`org.graalvm.sdk:graal-sdk`.\n\nThe library in this project uses the [Neo4j Java Driver](https://github.com/neo4j/neo4j-java-driver) to \nconnect against a Neo4j instance and exeecute a single query.\n\nThe entry point to the shared library is defined in `org.neo4j.examples.drivernative.DriverNativeLib`\nand looks like this:\n\n```java\n@CEntryPoint(name = \"execute_query_and_print_results\")\npublic static long executeQueryAndPrintResults(\n    IsolateThread isolate, CCharPointer uri, CCharPointer password, CCharPointer query\n) {\n    // Some interaction with the driver and Neo4j.\n    return 4711L;\n}\n```\n\nThe `@CEntryPoint` defines the entrypoint. Non trivial types are passed as pointers from the outside.\nThe `IsolateThread` is a control structure *required* as first argument by GraalVM.\n\nThe last ingredience to create a shared library is the appropriate flag to the `native-image` tool:\n`--shared -H:Name=libneo4j` which is applied in the `pom.xml`.\n\nOn macOS the following artifacts are build\n\n```\ngraal_isolate.h\ngraal_isolate_dynamic.h\nlibneo4j.dylib\nlibneo4j.h\nlibneo4j_dynamic.h\n```\n\nand can be used for example from C or through FFI in Ruby or Rust.\n\n### Start a Neo4j Docker instance\n\n```\ndocker run --publish=7474:7474 --publish=7687:7687 -e 'NEO4J_AUTH=neo4j/secret' -e NEO4J_ACCEPT_LICENSE_AGREEMENT=yes neo4j:4.0\n```\n\n### Install GraalVM\n\nDownload the JDK 11 version for your operating system from\nhttps://github.com/oracle/graal/releases\n\nAll community downloads are available on\nhttps://github.com/graalvm/graalvm-ce-builds/releases\n\nHere we used version 20.1.0\n\nExports should be as follows:\n\n```\nexport GRAALVM_HOME=/Library/Java/JavaVirtualMachines/graalvm-ce-java11-20.1.0/Contents/Home\nexport PATH=$PATH:$GRAALVM_HOME/bin\nexport JAVA_HOME=$GRAALVM_HOME\n```\n\nThen install the native image tool\n\n```\ngu install native-image\ngu list\n```\n\n### Build the project\n\n```\n./mvnw clean package \n```\n\n#### Usage from C\n\nPlease have a look at [`src/main/c/executeQuery.c`](https://github.com/michael-simons/neo4j-java-driver-native-lib/blob/master/src/main/c/executeQuery.c). \nThe following is tested with:\n\n```\ngcc --version\nApple clang version 12.0.0 (clang-1200.0.32.2)\nTarget: x86_64-apple-darwin19.6.0\n```\n\nOn macOS: Compile from the project roots with\n\n```\ngcc -Wall -Isrc/main/native -Ltarget -Itarget target/libneo4j.dylib src/main/c/executeQueryAndPrintResults.c -o target/executeQueryAndPrintResults\n```\n\nAnd run as\n\n```\ntarget/executeQueryAndPrintResults\n```\n\n#### Usage from Ruby\n\nPlease have a look at [`src/main/ruby/executeQuery.rb`](https://github.com/michael-simons/neo4j-java-driver-native-lib/blob/master/src/main/ruby/executeQuery.rb). \nThe following is tested with:\n\n```\nruby --version\nruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin19]\n```\n\nYou need to have the Ruby `ffi` gem installed (via `gem install ffi`).\nWith FFI in place, run the script like this (from the root of this repository):\n\n```\nruby src/main/ruby/executeQueryAndPrintResults.rb\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichael-simons%2Fneo4j-java-driver-native-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichael-simons%2Fneo4j-java-driver-native-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichael-simons%2Fneo4j-java-driver-native-lib/lists"}