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

Export rocksdb fuctions in rocksdbjni.dll #12246

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/windows-build-steps/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ runs:
$env:Path = $env:JAVA_HOME + ";" + $env:Path
mkdir build
cd build
& cmake -G "$Env:CMAKE_GENERATOR" -DCMAKE_BUILD_TYPE=Debug -DOPTDBG=1 -DPORTABLE="$Env:CMAKE_PORTABLE" -DSNAPPY=1 -DJNI=1 ..
& cmake -G "$Env:CMAKE_GENERATOR" -DCMAKE_BUILD_TYPE=Debug -DOPTDBG=1 -DPORTABLE="$Env:CMAKE_PORTABLE" -DSNAPPY=1 -DJNI=1 -DWITH_JNI_EXPORT_ROCKSDB=1 ..
if(!$?) { Exit $LASTEXITCODE }
cd ..
echo "Building with VS version: $Env:CMAKE_GENERATOR"
Expand Down
28 changes: 28 additions & 0 deletions build_tools/extract-exported-functions.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Param(
[Parameter(Mandatory = $true)]
[string]$InputFile = $null,

[Parameter(Mandatory = $true)]
[string]$OutputPath = $null
)

Write-Host "InputFile : $InputFile"
Write-Host "OutputPath : $OutputPath"

$regexPattern = "^ *\d+ +[0-9A-F]+ [0-9A-F]+ (rocksdb_[a-zA-Z_0-9]+).*$"

$extractedValues = @()
$extractedValues += "LIBRARY ROCKSJNI"
$extractedValues += "EXPORTS"

$fileContent = Get-Content -Path $InputFile
foreach ($line in $fileContent)
{
if ($line -match $regexPattern)
{
$extractedData = $Matches[1]
$extractedValues += $extractedData
}
}
$extractedValues | Out-File -FilePath $OutputPath -Encoding utf8
Write-Host "Extraction completed. Extracted values are stored in $OutputPath."
36 changes: 34 additions & 2 deletions java/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -789,20 +789,52 @@ if(NOT MSVC)
set_property(TARGET ${ROCKSDB_STATIC_LIB} PROPERTY POSITION_INDEPENDENT_CODE ON)
endif()

option(WITH_JNI_EXPORT_ROCKSDB "Export ROCKSDB namespace in rocksdbjni.dll (Only on Windows)" OFF)
if(WITH_JNI_EXPORT_ROCKSDB)
message("CMAKE_CXX_COMPILER : ${CMAKE_CXX_COMPILER}")

set(VC_DUMPBIN_HINT ${CMAKE_CXX_COMPILER})
cmake_path(REMOVE_FILENAME VC_DUMPBIN_HINT)

message("VC_DUMPBIN_HINT : ${VC_DUMPBIN_HINT}")
find_program(
VC_DUMPBIN dumpbin
HINTS ${VC_DUMPBIN_HINT}
REQUIRED
)
message("VC_DUMPBIN : ${VC_DUMPBIN}")

set(ROCKSDBJNIDEF rocksdbjnidef)
set(ROCKSDBJNI_DEF_FILENAME rocksdbjni.def)

add_custom_target(${ROCKSDBJNIDEF}
COMMAND ${VC_DUMPBIN} /exports /OUT:dumpbin.raw $<TARGET_FILE:${ROCKSDB_SHARED_LIB}>
COMMAND powershell "${CMAKE_SOURCE_DIR}/build_tools/extract-exported-functions.ps1"
-InputFile ${CMAKE_CURRENT_BINARY_DIR}/dumpbin.raw
-OutputPath ${CMAKE_CURRENT_BINARY_DIR}/${ROCKSDBJNI_DEF_FILENAME}
DEPENDS ${ROCKSDB_SHARED_LIB}
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/${ROCKSDBJNI_DEF_FILENAME}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating ${ROCKSDBJNI_DEF_FILENAME}"
VERBATIM
)
list(APPEND JNI_NATIVE_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/${ROCKSDBJNI_DEF_FILENAME})
endif ()

set(ROCKSDBJNI_STATIC_LIB rocksdbjni${ARTIFACT_SUFFIX})
if(MINGW)
# Build mingw only as staic library.
add_library(${ROCKSDBJNI_STATIC_LIB} ${JNI_NATIVE_SOURCES})
else()
add_library(${ROCKSDBJNI_STATIC_LIB} SHARED ${JNI_NATIVE_SOURCES})
endif()
add_dependencies(${ROCKSDBJNI_STATIC_LIB} rocksdbjni_headers)
add_dependencies(${ROCKSDBJNI_STATIC_LIB} rocksdbjni_headers ${ROCKSDBJNIDEF})
target_link_libraries(${ROCKSDBJNI_STATIC_LIB} ${ROCKSDB_STATIC_LIB} ${ROCKSDB_LIB})

if(NOT MINGW)
set(ROCKSDBJNI_SHARED_LIB rocksdbjni-shared${ARTIFACT_SUFFIX})
add_library(${ROCKSDBJNI_SHARED_LIB} SHARED ${JNI_NATIVE_SOURCES})
add_dependencies(${ROCKSDBJNI_SHARED_LIB} rocksdbjni_headers)
add_dependencies(${ROCKSDBJNI_SHARED_LIB} rocksdbjni_headers ${ROCKSDBJNIDEF})
target_link_libraries(${ROCKSDBJNI_SHARED_LIB} ${ROCKSDB_STATIC_LIB} ${ROCKSDB_LIB})

set_target_properties(
Expand Down
Loading