Skip to content

Commit

Permalink
build: graalvm build
Browse files Browse the repository at this point in the history
olavloite committed Jan 8, 2025
1 parent 40b2cb7 commit b702933
Showing 5 changed files with 50 additions and 2 deletions.
10 changes: 10 additions & 0 deletions build/native-image/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
mvn clean
mvn package -P assembly -DskipTests
cd target/pgadapter
native-image \
--shared \
--initialize-at-build-time=com.google.protobuf,com.google.gson \
-J-Xmx14g -H:IncludeResources=".*metadata.*json$" \
-H:ReflectionConfigurationFiles=../../build/native-image/reflectconfig.json \
-jar pgadapter.jar \
--no-fallback
19 changes: 19 additions & 0 deletions build/native-image/reflectconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[
{
"name" : "java.lang.Class",
"queryAllDeclaredConstructors" : true,
"queryAllPublicConstructors" : true,
"queryAllDeclaredMethods" : true,
"queryAllPublicMethods" : true,
"allDeclaredClasses" : true,
"allPublicClasses" : true
},
{
"name" : "java.time.Instant",
"methods" : [
{ "name" : "now" },
{ "name" : "getNano" },
{ "name" : "getEpochSecond" }
]
}
]
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -93,6 +93,10 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.graalvm.sdk</groupId>
<artifactId>graal-sdk</artifactId>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner</artifactId>
17 changes: 17 additions & 0 deletions src/main/java/com/google/cloud/spanner/pgadapter/Server.java
Original file line number Diff line number Diff line change
@@ -57,6 +57,10 @@
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;
import org.graalvm.nativeimage.IsolateThread;
import org.graalvm.nativeimage.c.function.CEntryPoint;
import org.graalvm.nativeimage.c.type.CCharPointer;
import org.graalvm.nativeimage.c.type.CTypeConversion;

/** Effectively this is the main class */
public class Server {
@@ -85,6 +89,19 @@ public static void main(String[] args) {
}
}

@CEntryPoint(name = "start")
public static void start(IsolateThread thread, CCharPointer cArguments) {
String arguments = CTypeConversion.toJavaString(cArguments);
String[] args = arguments.split(" ");
try {
OptionsMetadata optionsMetadata = extractMetadata(args, System.out);
ProxyServer proxyServer = new ProxyServer(optionsMetadata, OpenTelemetry.noop());
proxyServer.startServer();
} catch (Exception e) {
printError(e, System.err, System.out);
}
}

/**
* Registers signal handlers for TERM, INT, and QUIT. This method uses reflection and fails
* gracefully if signal handling is not available on this JVM.
2 changes: 0 additions & 2 deletions wrappers/golang/go.sum
Original file line number Diff line number Diff line change
@@ -144,8 +144,6 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ=
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
golang.org/x/oauth2 v0.24.0 h1:KTBBxWqUa0ykRPLtV69rRto9TLXcqYkeswu48x/gvNE=
golang.org/x/oauth2 v0.24.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/oauth2 v0.25.0 h1:CY4y7XT9v0cRI9oupztF8AgiIu99L/ksR/Xp/6jrZ70=
golang.org/x/oauth2 v0.25.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=

0 comments on commit b702933

Please sign in to comment.