Skip to content

Commit fa6789b

Browse files
committed
BUG#34370637 Replacing Google V8 with Oracle GraalVM
Oracle GraalVM is now used in the MySQL Shell to expose the different APIs into a JavaScript execution interface. This is an in-place replacement, no additional functionality is being provided with this update. Change-Id: Iefc2ac2d3c1b70426200ab238e68d5005dc03e25
1 parent 49abf86 commit fa6789b

File tree

136 files changed

+12397
-2237
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+12397
-2237
lines changed

CMakeLists.txt

Lines changed: 18 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,24 @@ if(HAVE_PYTHON)
755755
ENDIF()
756756
endif()
757757

758+
IF (BUNDLED_POLYGLOT_DIR)
759+
FIND_LIBRARY(POLYGLOT_LIBRARY
760+
NAMES
761+
polyglot
762+
HINTS
763+
"${BUNDLED_POLYGLOT_DIR}"
764+
NO_DEFAULT_PATH)
765+
766+
INCLUDE_DIRECTORIES(SYSTEM "${BUNDLED_POLYGLOT_DIR}")
767+
MESSAGE(STATUS "Polyglot Library: ${POLYGLOT_LIBRARY}")
768+
SET(HAVE_JS 1)
769+
SET(HAVE_POLYGLOT 1)
770+
ADD_DEFINITIONS(-DHAVE_JS)
771+
ADD_DEFINITIONS(-DHAVE_POLYGLOT)
772+
ENDIF()
773+
774+
775+
758776
IF(WIN32)
759777
# Speed up build process excluding unused header files
760778
# Also definitely resolves the trouble of using both
@@ -798,15 +816,6 @@ ELSE()
798816
SET(WITH_DEV "1")
799817
ENDIF()
800818

801-
IF(V8_INCLUDE_DIR AND V8_LIB_DIR)
802-
set(HAVE_V8 "YES") # Variable for CMake processing
803-
add_definitions(-DHAVE_V8) # Preprocessor variable for generated projects
804-
add_definitions(-DV8_DEPRECATION_WARNINGS)
805-
add_definitions(-DV8_IMMINENT_DEPRECATION_WARNINGS)
806-
ELSE()
807-
message(WARNING "V8 is unavailable: building without JavaScript support.")
808-
ENDIF()
809-
810819
IF(PYTHONLIBS_FOUND OR BUNDLED_PYTHON_DIR)
811820
set(HAVE_PYTHON "YES") # Variable for CMake processing
812821
IF(BUNDLED_PYTHON_DIR)
@@ -1175,54 +1184,6 @@ find_package(libssh 0.9.2 REQUIRED)
11751184

11761185
message(STATUS "Found libssh: ${libssh_VERSION}, using config: ${libssh_CONFIG}")
11771186

1178-
if(HAVE_V8)
1179-
find_library(V8_LIB v8_monolith
1180-
PATHS ${V8_LIB_DIR}
1181-
NO_DEFAULT_PATH
1182-
)
1183-
set(V8_LIBS)
1184-
if(V8_LIB)
1185-
set(V8_LIBS ${V8_LIB}) # Single lib, just use it
1186-
message(STATUS "v8 Library Found: \"v8_monolith\" at ${V8_LIB}")
1187-
else()
1188-
# Could not find monolith library, try separate libs
1189-
if(WIN32)
1190-
# on Windows libraries could have .dll.lib extensions
1191-
SET(ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
1192-
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".lib" ".dll.lib")
1193-
endif()
1194-
foreach(_libname v8 v8_libbase v8_libplatform)
1195-
find_library(_v8_lib ${_libname}
1196-
PATHS ${V8_LIB_DIR}
1197-
NO_DEFAULT_PATH
1198-
)
1199-
if(NOT _v8_lib)
1200-
message(FATAL_ERROR "Could not find the library \"v8_monolith\" or \"${_libname}\" in ${V8_LIB_DIR}")
1201-
else()
1202-
message(STATUS "v8 Library Found: \"${_libname}\" at ${_v8_lib}")
1203-
endif()
1204-
list(APPEND V8_LIBS ${_v8_lib})
1205-
UNSET(_v8_lib CACHE)
1206-
endforeach()
1207-
if(WIN32)
1208-
# restore original extensions
1209-
SET(CMAKE_FIND_LIBRARY_SUFFIXES ${ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
1210-
endif()
1211-
if(NOT WIN32 AND NOT APPLE)
1212-
# newer versions of linker enable new dtags by default, causing -Wl,-rpath to create RUNPATH entry instead of RPATH
1213-
# this results in loader being unable to find v8_libbase, as it's a transitive dependency of v8 and v8_libplatform
1214-
# disable new dtags on debug builds, so resultant executable is usable without LD_LIBRARY_PATH
1215-
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -Wl,--disable-new-dtags")
1216-
endif()
1217-
endif()
1218-
1219-
if(WIN32)
1220-
set(V8_LINK_LIST ${V8_LIBS} winmm dbghelp shlwapi)
1221-
else() # Linux
1222-
set(V8_LINK_LIST ${V8_LIBS})
1223-
endif()
1224-
endif()
1225-
12261187
add_definitions(-DMYSH_VERSION="${MYSH_VERSION}" -DMYSH_BUILD_ID="${MYSH_BUILD_ID}" -DEXTRA_NAME_SUFFIX="${EXTRA_NAME_SUFFIX}")
12271188
if(WIN32)
12281189
add_definitions(-DMYSH_VERSION_WIN="${MYSH_VERSION_WIN}")

INSTALL

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Dependencies
77
Mandatory
88
- cmake 3.5.1 (note: if you're using a very recent version of cmake and it
99
doesn't work, try downgrading)
10-
- gcc 5/VisualStudio 2015/clang 8
10+
- gcc 10/VisualStudio 2019/clang 10
1111
- MySQL client libraries built from sources
1212
(libmysqlclient, libmysqlxclient)
1313
- zip (gnuwin32 in windows)
@@ -16,7 +16,7 @@ Mandatory
1616

1717
Optional
1818
- gtest and gmock 1.8 (can be automatically downloaded)
19-
- v8 12.0.267.8
19+
- GraalVM 23.0.1
2020

2121
Building From Source
2222
====================
@@ -87,22 +87,26 @@ Windows
8787

8888
Enabling JavaScript Support
8989
---------------------------
90-
JavaScript is enabled by satisfying the dependency with V8.
91-
To build V8 follow the build V8 standard build instructions.
92-
To support JavaScript on the MySQL Shell add the next flags to the CMake call:
90+
JavaScript is enabled by satisfying the native Polyglot API library
91+
(From GraalVM) dependency.
9392

94-
-DHAVE_V8=1
93+
To build The native Polyglot API library follow the instructions at
94+
ext/polyglot/README.txt
9595

96-
-DV8_INCLUDE_DIR=<path_to_v8>/include
97-
-DV8_LIB_DIR=<path_to_folder_containing_the_built_libraries>
96+
To support JavaScript on the MySQL Shell add the following flag to the CMake call:
9897

99-
Note that version 12.0.267.8 is needed and newer versions may not work.
98+
-DBUNDLED_POLYGLOT_DIR=<Path>
99+
100+
Where Path is the path to the folder containing the native Polyglot API library
101+
and headers
102+
103+
Note that version 23.0.1 is needed and newer versions may not work.
100104

101105

102106
Enabling Python Support
103107
-----------------------
104108
Python is enabled by satisfying the dependency with Python.
105-
To support Python on the MySQL Shell add the next flags to the CMake call:
109+
To support Python on the MySQL Shell add the following flags to the CMake call:
106110

107111
-DHAVE_PYTHON=1
108112

cmake/exeutils.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ function(add_shell_executable)
100100
set_property(TARGET "${ARGV0}" PROPERTY PROPERTY BUILD_WITH_INSTALL_RPATH TRUE)
101101
endif()
102102
endif()
103-
if(HAVE_V8)
103+
104+
if(HAVE_JS)
104105
# strip the whole binary on 32bit Ubuntu 18.04, avoid OOM linker errors
105106
if(LINUX_UBUNTU_18_04 AND CMAKE_SIZEOF_VOID_P EQUAL 4)
106107
MY_TARGET_LINK_OPTIONS("${ARGV0}" "LINKER:--strip-all")

ext/polyglot/README.txt

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
This project builds a native version of the GraalVM Polyglot Native API Library
2+
with some enhancements required for the proper integration of GraalVM as a
3+
JavaScript runtime on the MySQL Middleware Clients.
4+
5+
The library is assembled by taking the official code for the GraalVM Polyglot
6+
Native API Library sources and exporting additional functionality through the
7+
use of a patch file contained in the polyglot-nativeapi/patches directory.
8+
9+
For details about how to update this library to meet additional requirements on
10+
the MySQL Middleware clients, refer to the README.txt file at the
11+
polyglot-nativeapi folder.
12+
13+
BUILD REQUIREMENTS
14+
------------------
15+
16+
To build the native version of the GraalVM Polyglot Native API created with
17+
this project the following requirements should be met:
18+
19+
- GraalVM 23.0.1 Installed and in PATH (to execute the native-image command)
20+
- The GraalVM 23.0.1 source code.
21+
- The JAVA_HOME environment variable set to the Home folder of the GraalVM JDK.
22+
- Maven available: verify with mvn --version
23+
- The environment variable GRAALJDK_ROOT set to the path where the GraalVM JDK
24+
source code is unpacked.
25+
26+
BUILDING THE PROJECT
27+
--------------------
28+
29+
In a shell terminal at the location of this README.txt file execute the
30+
following command:
31+
32+
$ mvn package
33+
34+
This command will execute the following steps:
35+
36+
- 1) Copy the GraalVM Polyglot API sources from GRAALJDK_ROOT to this project.
37+
- 2) Apply the patches in the polyglot-nativeapi/patches folder to the copied
38+
sources.
39+
- 3) Build the native library for the GraalVM Polyglot Native API
40+
41+
The native library for the GraalVM Polyglot Native API library will be built at
42+
the following path:
43+
44+
polyglot-nativeapi-native-library/target
45+
46+
CLEANING THE BUILD
47+
------------------
48+
49+
Cleaning the build would delete all the compiled binaries but let the patched
50+
source code ready to build again, this is, the code that was extracted from
51+
the original GraalVM sources and then patched will stay ready for a new build.
52+
53+
Thi can be achieved by executing:
54+
55+
$ mvn clean
56+
57+
To completely reset the project to it's initial state, execute:
58+
59+
$ mvn -Ddev clean
60+
61+
62+
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>org.graalvm.polyglot.library</groupId>
9+
<artifactId>mysql-middleware-polyglot-library-bundle</artifactId>
10+
<version>1.0-SNAPSHOT</version>
11+
</parent>
12+
13+
<groupId>org.graalvm.polyglot.library</groupId>
14+
<artifactId>polyglot-nativeapi-native-library</artifactId>
15+
<version>1.0-SNAPSHOT</version>
16+
<packaging>pom</packaging>
17+
18+
<properties>
19+
<maven.compiler.target>22</maven.compiler.target>
20+
<maven.compiler.source>22</maven.compiler.source>
21+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22+
</properties>
23+
24+
<dependencies>
25+
26+
<dependency>
27+
<groupId>org.graalvm.polyglot</groupId>
28+
<artifactId>polyglot</artifactId>
29+
<version>${graalvm.version}</version>
30+
</dependency>
31+
32+
<dependency>
33+
<groupId>org.graalvm.polyglot.library</groupId>
34+
<artifactId>polyglot-nativeapi</artifactId>
35+
<version>1.0-SNAPSHOT</version>
36+
</dependency>
37+
38+
</dependencies>
39+
40+
<build>
41+
<directory>${project.build.directory.override}</directory>
42+
<plugins>
43+
<plugin>
44+
<artifactId>exec-maven-plugin</artifactId>
45+
<groupId>org.codehaus.mojo</groupId>
46+
<version>3.1.0</version>
47+
<executions>
48+
<execution>
49+
<id>prepare-output-dir</id>
50+
<phase>package</phase>
51+
<goals>
52+
<goal>exec</goal>
53+
</goals>
54+
<configuration>
55+
<executable>
56+
${mkdir.command}
57+
</executable>
58+
<commandlineArgs>
59+
${mkdir.args} ${project.build.directory}
60+
</commandlineArgs>
61+
<successCodes>
62+
<successCode>0</successCode>
63+
<successCode>1</successCode>
64+
</successCodes>
65+
</configuration>
66+
</execution>
67+
<execution>
68+
<id>build-polyglot-library</id>
69+
<phase>package</phase>
70+
<goals>
71+
<goal>exec</goal>
72+
</goals>
73+
<configuration>
74+
<executable>
75+
${env.JAVA_HOME}${file.separator}bin${file.separator}${native-image.command}
76+
</executable>
77+
<commandlineArgs>
78+
-p %classpath
79+
-H:+ReportExceptionStackTraces
80+
-o ${project.build.directory}${file.separator}libpolyglot
81+
--no-fallback
82+
--shared
83+
-H:+UnlockExperimentalVMOptions
84+
-H:-PerfDataMemoryMappedFile
85+
-H:-SupportCompileInIsolates
86+
-H:AlignedHeapChunkSize=128k
87+
-H:LargeArrayThreshold=32k
88+
--enable-monitoring=jvmstat
89+
-H:+ReportExceptionStackTraces
90+
-H:+PreserveFramePointer
91+
-H:-DeleteLocalSymbols
92+
-H:+AsyncSignalSafeDiagnostics
93+
-H:+IgnoreMaxHeapSizeWhileInVMOperation
94+
-H:-UnlockExperimentalVMOptions
95+
-R:SpectrePHTBarriers=GuardTargets
96+
-J-Xmx20g
97+
--initialize-at-run-time=org.graalvm.polyglot.nativeapi.PolyglotNativeAPI$NativeDataHolder
98+
--verbose
99+
</commandlineArgs>
100+
</configuration>
101+
</execution>
102+
</executions>
103+
</plugin>
104+
</plugins>
105+
</build>
106+
<repositories>
107+
<repository>
108+
<id>artifactory.libs-release</id>
109+
<url>https://artifactory.oci.oraclecorp.com/libs-release</url>
110+
</repository>
111+
</repositories>
112+
<pluginRepositories>
113+
<pluginRepository>
114+
<id>artifactory.libs-release</id>
115+
<url>https://artifactory.oci.oraclecorp.com/libs-release</url>
116+
</pluginRepository>
117+
</pluginRepositories>
118+
</project>

0 commit comments

Comments
 (0)