Skip to content

Commit

Permalink
Merge pull request #12 from bpintea/feature/deps_as_subtrees
Browse files Browse the repository at this point in the history
Add dependencies as subtrees
  • Loading branch information
bpintea authored Aug 10, 2018
2 parents 4425c09 + fa3634f commit b5e999a
Show file tree
Hide file tree
Showing 3,025 changed files with 488,468 additions and 259 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
62 changes: 30 additions & 32 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,65 +139,58 @@ endif (${CMD_RETURN})
#
# add ODBC-Specification to the project
#
# TODO: add this as a git subtree and/or as ExternalProject
set(ODBC_PATH_SRC ${CMAKE_SOURCE_DIR}/libs/ODBC-Specification CACHE PATH
"ODBC-Specification source path")
if (NOT IS_DIRECTORY ${ODBC_PATH_SRC})
message(FATAL_ERROR "No ODBC-Specification directory found: use "
"ODBC_PATH_SRC cmake option or place an 'ODBC-Specification' "
"clone into local 'lib' dir.")
endif (NOT IS_DIRECTORY ${ODBC_PATH_SRC})
message("ODBC-Specification source path: ${ODBC_PATH_SRC} .")
set(ODBC_INC ${ODBC_PATH_SRC}/Windows/inc)


#
# add ujson4c to the project
#
# TODO: add this as a git subtree and/or as ExternalProject (with patching)
set(UJSON4C_PATH_SRC ${CMAKE_SOURCE_DIR}/libs/ujson4c CACHE PATH
"Lib ujson4c source path")
if (NOT IS_DIRECTORY ${UJSON4C_PATH_SRC})
message(FATAL_ERROR "No ujson4c directory found: use UJSON4C_PATH_SRC "
"cmake option or place an 'ujson4c' clone into local 'libs' dir.")
endif (NOT IS_DIRECTORY ${UJSON4C_PATH_SRC})
message("Lib ujson4c source path: ${UJSON4C_PATH_SRC} .")
aux_source_directory(${UJSON4C_PATH_SRC}/src DRV_SRC)
aux_source_directory(${UJSON4C_PATH_SRC}/3rdparty DRV_SRC)
set(UJSON4C_INC ${UJSON4C_PATH_SRC}/src ${UJSON4C_PATH_SRC}/3rdparty )

#
# add c-timestamp to the project
#
# TODO: add this as a git subtree and/or as ExternalProject
set(CTIMESTAMP_PATH_SRC ${CMAKE_SOURCE_DIR}/libs/c-timestamp CACHE PATH
"Lib c-timestamp source path")
if (NOT IS_DIRECTORY ${CTIMESTAMP_PATH_SRC})
message(FATAL_ERROR "No c-timestamp directory found: use "
"CTIMESTAMP_PATH_SRC cmake option or place a 'c-timestamp' clone "
"in local 'lib' dir.")
endif (NOT IS_DIRECTORY ${CTIMESTAMP_PATH_SRC})
message("Lib c-timestamp source path: ${CTIMESTAMP_PATH_SRC} .")
aux_source_directory(${CTIMESTAMP_PATH_SRC}/ DRV_SRC)

#
# add libcurl to the project
#
# TODO: add this as a git subtree and/or as ExternalProject
set(LIBCURL_PATH_SRC ${CMAKE_SOURCE_DIR}/libs/curl CACHE PATH
"Lib curl source path")
set(LIBCURL_LD_PATH
# curl "installs" the .dll and .lib in different directories -> use the
# build dir to find both files in same directory instead of installing
${CMAKE_SOURCE_DIR}/libs/curl/builds/libcurl-vc-${TARCH}-release-dll-ipv6-sspi-winssl-obj-lib/
# Curl "installs" the .dll and .lib in different directories -> use the
# build dir to find both files in same directory instead of installing.
# Curl's win build root directory is not configurable.
# The path built below is only constant for the subtree tag (current:
# 7.61.0) and it's default nmake options (only with: IPv6, SSPI, WinSSL).
${LIBCURL_PATH_SRC}/builds/libcurl-vc-${TARCH}-release-dll-ipv6-sspi-winssl-obj-lib/
CACHE PATH "Lib curl load library path")
set(LIBCURL_INC_PATH ${CMAKE_SOURCE_DIR}/libs/curl/include CACHE PATH
set(LIBCURL_INC_PATH ${LIBCURL_PATH_SRC}/include CACHE PATH
"Lib curl include path")
if (NOT IS_DIRECTORY ${LIBCURL_LD_PATH}
OR NOT IS_DIRECTORY ${LIBCURL_INC_PATH})
message(FATAL_ERROR "Missing libcurl lib and/or inc directories: use "
"LIBCURL_LD_PATH and LIBCURL_INC_PATH cmake options or place a built "
"'curl' clone in local 'libs' dir.")
endif()
message("Curl paths load lib: ${LIBCURL_LD_PATH}, inc: ${LIBCURL_INC_PATH} .")
if (NOT IS_DIRECTORY ${LIBCURL_LD_PATH})
# Note: building libcurl happens at config time (as a pre-requisite), for
# now. This might be changed to a build target later.
# TODO: add non-WiN32 building.
execute_process(COMMAND buildconf.bat
WORKING_DIRECTORY "${LIBCURL_PATH_SRC}"
)
if (NOT ${CMD_RETURN})
execute_process(COMMAND nmake /f Makefile.vc mode=dll MACHINE=${TARCH}
WORKING_DIRECTORY "${LIBCURL_PATH_SRC}/winbuild"
)
endif (NOT ${CMD_RETURN})
if (${CMD_RETURN})
message(FATAL_ERROR "Building libcurl failed:")
endif (${CMD_RETURN})
endif(NOT IS_DIRECTORY ${LIBCURL_LD_PATH})
# add libcurl as dependency
add_library(libcurl SHARED IMPORTED)
if (${WIN32})
Expand All @@ -210,6 +203,11 @@ else (${WIN32})
${LIBCURL_LD_PATH}/libcurl${CMAKE_SHARED_LIBRARY_SUFFIX})
endif (${WIN32})

add_custom_target(curlclean
COMMAND nmake /f Makefile.vc mode=dll clean
WORKING_DIRECTORY "${LIBCURL_PATH_SRC}/winbuild"
)


message("Driver source files: ${DRV_SRC} .")
message("Driver include paths: " ${ODBC_INC} ${DRV_SRC_DIR}
Expand Down
99 changes: 24 additions & 75 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
# ODBC Driver for Elastic SQL

This is the ODBC driver for Elastic's SQL engine.
This is the ODBC driver for Elasticsearch's SQL plugin.
The driver implements the Unicode version of the 3.80 API release.

## Supported platforms

The current target platform is Microsoft Windows, past and including version 7. The 32bits version of the driver is currently developped.
Full support should include Linux and OSX, on both x86 and amd64 architectures.
The current target platform is Microsoft Windows, past and including version 7.
Full support will include Linux and OSX, on both x86 and amd64 architectures.

## Running Requirements

On the client side, the ODBC driver requires the OS'es Driver Manager to
interface between the clients and the driver itself.
On the server side, the requirements follow Elastic SQL's requirements.
On the server side, the requirements follow Elasticsearch SQL's requirements.

## Building Requirements

### CMake

The project is CMake enabled, which generates the environment-dependent build
pipeline. This is a general build requirement.
CMake version: 2.8.6 or later.

The building itself is then delegated to the platform-specific tools (MSVC or
make).
Expand All @@ -34,13 +33,29 @@ The driver makes use of the following libraries/headers:
including the headers defining the ODBC C API;
* libcurl
- the library is used for the HTTP(S) communication with Elasticsearch REST
endpoints;
endpoint;
* c-timestamp
- the library is used for parsing the ISO 8601 formated timestamps received
from Elasticsearch;
* ujson4c
- fast scanner library for JSON.

The required libraries are added as subtrees to the project, in the libs directory:
```
somedirectory\
|_elasticsearch-sql-odbc
|_README.md
|_CMakeLists.txt
|_build.bat
|_driver
|_builds
|_libs
|_ODBC-Specification
|_curl
|_c-timestamp
|_ujson4c
```


### Windows

Expand Down Expand Up @@ -79,71 +94,6 @@ since Windows' shared objects symbols are by default not exported.

## Building

### Libraries

The libraries need to be cloned locally and the indicated revision and one
built, as indicated below.
The cloning can be done arbitrarily on the disk and then the corresponding
paths indicated in environment variables. The simplest way though is to export
them in driver's libs directory, where the build script expects them by
default:
```
somedirectory\
|_elasticsearch-sql-odbc
|_README.md
|_CMakeLists.txt
|_build.bat
|_driver
|_builds
|_libs
|_ODBC-Specification
|_curl
|_c-timestamp
|_ujson4c
```

#### ODBC-Specification

Clone the project *https://github.com/Microsoft/ODBC-Specification.git*.
The headers is revised with C defines, so the project can be left at *master*
revision.


#### libcurl

The library needs to be exported and compiled, since the driver will be linked
against it. The driver has been tested against release 7.58.0 of the library.

The following steps will export and build the library (for a 64 bits build):
```
> cd libs
> git clone https://github.com/curl/curl.git
> cd curl
> git checkout curl-7_58_0
> .\buildconf.bat
> cd .\winbuild\
> nmake /f Makefile.vc mode=dll MACHINE=x64
> dir ..\builds\libcurl-vc-x64-release-dll-ipv6-sspi-winssl\bin
```
If the build was succesfull, the last step will show the libcurl.dll file.

#### c-timestamp

Clone the project *https://github.com/chansen/c-timestamp.git*.
Current (Feb 2018) *master* branch should be used.

#### ujson4c

Clone the project *https://github.com/esnme/ujson4c.git*.
Current (Feb 2018) *master* branch should be used. The library contains two
currently unpatched defects ([[9]](https://github.com/esnme/ujson4c/issues/9),
[[10]](https://github.com/esnme/ujson4c/issues/10)). Driver's top directory
contains a patch *ujson4c.diff* that needs to be applied before building the
driver; using GnuWin *patch* utility (that handles well Win's CRLF):
```
> patch -p1 -i .\ujson4c.diff -d .\ujson4c
```

### Windows MSVC

Start Visual Studio and menu-access File > Open > "CMake..". Navigate to the checkout folder of the project and select the file CMakeLists.txt.
Expand All @@ -159,10 +109,9 @@ Some environment parameters can be set to customized its behavior (see start
of script).

The script can also take a set of parameters, run ```build.bat help``` to see
what they mean. ```build.bat fetch``` will fetch all required libraries, patch
and build them, where necessary, then build the driver itself, by invoking
CMake and MSBuild, as needed.
what they mean. ```build.bat``` will build the driver itself, by invoking
CMake and MSBuild, as needed. ```build.bat proper``` will clean the project to initial state. ```build.bat all tests``` will run the unit tests.

## Installation

The driver will be provided with the Windows installer for Elastic X-Pack.
[TODO]
73 changes: 12 additions & 61 deletions build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,15 @@ REM USAGE function: output a usage message
echo setup : invoke MSVC's build environment setup script before
echo building (requires 2017 version or later^).
echo clean : remove all the files in the build dir.
echo proper : clean both the build and libs dir and exit.
echo fetch : fetch, patch and build the dependency libs.
echo proper : clean both the libs and builds dirs and exit.
echo nobuild : skip project building (the default is to build^).
echo type=T : selects the build type; T can be one of Debug/Release/
echo RelWithDebInfo/MinSizeRel^); defaults to Debug.
echo exports : dump the exported symbols in the DLL after - and
echo only if - building the driver.
echo all : build all artifacts (driver and tests^).
echo tests : run all the defined tests: invoke the 'all' build,
echo then the 'tests' build.
echo tests : run all the defined tests: invoke the 'all' build
echo before the 'tests' build!
echo suites : compile and run each test individually, stopping at the
echo first failure; the 'all' or 'test' targets must be
echo built beforehand.
Expand All @@ -254,7 +253,7 @@ REM USAGE function: output a usage message
echo.
echo Multiple arguments can be used concurrently.
echo Invoked with no arguments, the script will only initiate a build.
echo Example:^> %1 setup 32 fetch
echo Example:^> %1 setup 32 tests
echo.
echo List of read environment variables:
echo BUILD_DIR : folder path to build the driver into;
Expand All @@ -270,20 +269,20 @@ REM USAGE function: output a usage message
goto:eof


REM PROPER function: clean up the build and libs dir before building
REM PROPER function: clean up the build and libs dir.
:PROPER
echo Cleaning all build and libs files.
del /s /q %BUILD_DIR%\* >nul 2>&1
for /d %%i in (%BUILD_DIR%\*) do rmdir /s /q %%i >nul 2>&1
del /s /q libs\* >nul 2>&1
for /d %%i in (libs\*) do rmdir /s /q %%i >nul 2>&1
echo Cleaning libs.
if exist %BUILD_DIR%\curlclean.vcxproj (
MSBuild %BUILD_DIR%\curlclean.vcxproj
)
call:CLEAN

goto:eof


REM CLEAN function: clean up the build dir before building
REM CLEAN function: clean up the build dir.
:CLEAN
echo Cleaning all build files.
echo Cleaning builds.
del /s /q %BUILD_DIR%\* >nul 2>&1
for /d %%i in (%BUILD_DIR%\*) do rmdir /s /q %%i >nul 2>&1

Expand Down Expand Up @@ -314,54 +313,6 @@ REM SETUP function: set-up the build environment
goto:eof


REM FETCH function: fetch, patch, build the external libs
:FETCH
echo Fetching external dependencies, patching and building them.

rem pushd .
cd libs

if not exist ODBC-Specification (
git clone "https://github.com/Microsoft/ODBC-Specification.git"
) else (
echo ODBC-Specification dir present, skipping cloning repo.
)
if not exist c-timestamp (
git clone "https://github.com/chansen/c-timestamp.git"
) else (
echo c-timestamp dir present, skipping cloning repo.
)
if not exist ujson4c (
git clone "https://github.com/esnme/ujson4c.git"

REM %cd% is expanded before execution and patch command will need full
REM path, as it might be started in different working dir than current
patch -p1 -i %cd%\ujson4c.diff -d %cd%\libs\ujson4c
) else (
echo ujson4c dir present, skipping cloning repo.
)
if not exist curl (
git clone "https://github.com/curl/curl.git"
) else (
echo curl dir present, skipping cloning repo.
)
if not exist googletest (
git clone "https://github.com/google/googletest.git"
) else (
echo googletest dir present, skipping cloning repo.
)

REM build libcurl
cd curl
git checkout curl-7_58_0

call buildconf.bat
REM buildconf.bat will cd
cd winbuild
call nmake /f Makefile.vc mode=dll MACHINE=!TARCH!

goto:eof

REM BUILDTYPE function: set the build config to feed MSBuild
:BUILDTYPE
REM cycle through the args, look for 'type' token and use the follow-up 1
Expand Down
3 changes: 0 additions & 3 deletions driver/build_def.bat
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,3 @@ echo.>> %OUTFILE%
echo EXPORTS>> %OUTFILE%
echo.>> %OUTFILE%
powershell -NoLogo -ExecutionPolicy Bypass -Command %FILTER%>> %OUTFILE%
echo.>> %OUTFILE%
REM minimize the exposure of this unwanted export
echo JSON_DecodeObject @1 NONAME PRIVATE>> %OUTFILE%
Loading

0 comments on commit b5e999a

Please sign in to comment.