Skip to content

Commit

Permalink
Build DuckDB (mc2-project#25)
Browse files Browse the repository at this point in the history
This PR downloads and builds DuckDB as a shared library to be linked to our enclave code. It defines a new task in build.sbt to first download the source files which is then compiled into a shared library by a very minimal CMakeLists.txt.
  • Loading branch information
octaviansima authored Apr 29, 2021
1 parent 9b9e394 commit fce6a66
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ sql/hive-thriftserver/test_warehouses
/private_key.pem
/public_key.pub
hs_err_pid*.log
/src/enclave/Thirdparty/*.cpp
/src/enclave/Thirdparty/Include/*.hpp

# Opaque generated data
/data/pagerank
Expand Down
26 changes: 26 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ val buildFlatbuffersTask = TaskKey[Seq[File]](

sourceGenerators in Compile += buildFlatbuffersTask.taskValue

val duckDBDownloadTask =
TaskKey[File]("duckDBDownload", "Downloads the DuckDB source file and corresponding header.")

val enclaveBuildTask = TaskKey[File](
"enclaveBuild",
"Builds the C++ enclave code, returning the directory containing the resulting shared libraries."
Expand Down Expand Up @@ -324,6 +327,7 @@ buildFlatbuffersTask := {

enclaveBuildTask := {
buildFlatbuffersTask.value // Enclave build depends on the generated C++ headers
duckDBDownloadTask.value // Enclave build depends on the downloaded third party sources
val enclaveSourceDir = baseDirectory.value / "src" / "enclave"
val enclaveBuildDir = target.value / "enclave"
enclaveBuildDir.mkdirs()
Expand All @@ -348,6 +352,28 @@ enclaveBuildTask := {
enclaveBuildDir / "lib"
}

duckDBDownloadTask := {
val enclaveThirdPartyDir = baseDirectory.value / "src" / "enclave" / "Thirdparty"
val duckDBInclude = enclaveThirdPartyDir / "Include"
if (!duckDBInclude.exists) {
Process(Seq("mkdir", duckDBInclude.getAbsolutePath), enclaveThirdPartyDir).!
}
val duckDBHpp = duckDBInclude / "duckdb.hpp"
val duckDBCpp = enclaveThirdPartyDir / "duckdb.cpp"
if (!duckDBHpp.exists || !duckDBCpp.exists) {
streams.value.log.info(s"Downloading DuckDB library for C++ Build")
val duckDBVersion = "0.2.5"
val duckDBUrl =
new java.net.URL(
s"https://github.com/cwida/duckdb/releases/download/v${duckDBVersion}/libduckdb-src.zip"
)
IO.unzipURL(duckDBUrl, enclaveThirdPartyDir)
Process(Seq("rm", "duckdb.h"), enclaveThirdPartyDir).!
Process(Seq("mv", "duckdb.hpp", "Include"), enclaveThirdPartyDir).!
}
enclaveThirdPartyDir
}

copyEnclaveLibrariesToResourcesTask := {
val libraries = (enclaveBuildTask.value ** "*.so").get
val mappings: Seq[(File, String)] =
Expand Down
2 changes: 2 additions & 0 deletions src/enclave/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ include_directories(ServiceProvider)
include_directories(${FLATBUFFERS_LIB_DIR})
include_directories(${FLATBUFFERS_GEN_CPP_DIR})
include_directories(${OE_INCLUDEDIR})
include_directories(Thirdparty/Include)

if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
Expand All @@ -45,3 +46,4 @@ add_custom_command(
add_subdirectory(App)
add_subdirectory(Enclave)
add_subdirectory(ServiceProvider)
add_subdirectory(Thirdparty)
1 change: 1 addition & 0 deletions src/enclave/Enclave/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ target_include_directories(enclave_trusted PRIVATE ${CMAKE_CURRENT_BINARY_DIR} $

link_directories(${OE_LIBDIR} ${OE_LIBDIR}/openenclave/enclave)
target_link_libraries(enclave_trusted
thirdparty
openenclave::oeenclave
openenclave::oecrypto${OE_CRYPTO_LIB}
openenclave::oelibc
Expand Down
11 changes: 11 additions & 0 deletions src/enclave/Thirdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This CMake will compile C++ files and headers generated by SBT
# that Opaque SQL's execution layer will need.
# Right now, the only such library is DuckDB.

project(Thirdparty)

include_directories(Include)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error")

add_library(thirdparty STATIC duckdb.cpp)

0 comments on commit fce6a66

Please sign in to comment.