diff --git a/build/native-image/build.sh b/build/native-image/build.sh new file mode 100644 index 0000000000..dde7fc9835 --- /dev/null +++ b/build/native-image/build.sh @@ -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 diff --git a/build/native-image/reflectconfig.json b/build/native-image/reflectconfig.json new file mode 100644 index 0000000000..d88e560770 --- /dev/null +++ b/build/native-image/reflectconfig.json @@ -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" } + ] + } +] diff --git a/pom.xml b/pom.xml index f5c5fd1b3e..edcf158157 100644 --- a/pom.xml +++ b/pom.xml @@ -93,6 +93,10 @@ + + org.graalvm.sdk + graal-sdk + com.google.cloud google-cloud-spanner diff --git a/src/main/java/com/google/cloud/spanner/pgadapter/Server.java b/src/main/java/com/google/cloud/spanner/pgadapter/Server.java index 361d6c39fc..2d834f98ef 100644 --- a/src/main/java/com/google/cloud/spanner/pgadapter/Server.java +++ b/src/main/java/com/google/cloud/spanner/pgadapter/Server.java @@ -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. diff --git a/wrappers/golang/go.sum b/wrappers/golang/go.sum index 0a79c42ce1..c4a7d0bcc7 100644 --- a/wrappers/golang/go.sum +++ b/wrappers/golang/go.sum @@ -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=