Skip to content

Commit

Permalink
feat: compiling on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
tshauck committed Jun 9, 2023
1 parent 82c271f commit 49ac97a
Show file tree
Hide file tree
Showing 19 changed files with 5,233 additions and 0 deletions.
460 changes: 460 additions & 0 deletions .gitignore

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "duckdb"]
path = duckdb
url = https://github.com/duckdb/duckdb.git
79 changes: 79 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
cmake_minimum_required(VERSION 3.2)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Set extension name here
set(TARGET_NAME exon)
set(EXTENSION_NAME ${TARGET_NAME}_extension)
set(CMAKE_CXX_STANDARD 11)

project(${TARGET_NAME})


Include(FetchContent)

FetchContent_Declare(
arrow
GIT_REPOSITORY https://github.com/apache/arrow.git
GIT_TAG apache-arrow-11.0.0
)

FetchContent_Declare(
httplib
GIT_REPOSITORY https://github.com/yhirose/cpp-httplib.git
GIT_TAG v0.12.0
)

FetchContent_Declare(
json
URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz
)

FetchContent_Declare(
Corrosion
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
GIT_TAG v0.3.5
)

FetchContent_Declare(
spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG v1.11.0
)

list(APPEND available_contents httplib json Corrosion spdlog arrow)

FetchContent_MakeAvailable(${available_contents})

corrosion_import_crate(MANIFEST_PATH rust/Cargo.toml
PROFILE release
)

include_directories(exon/include)
add_subdirectory(exon/src)

add_library(${EXTENSION_NAME} STATIC ${EXTENSION_SOURCES})

# Build extensions
set(PARAMETERS "-warnings")
build_loadable_extension(${TARGET_NAME} ${PARAMETERS} ${EXTENSION_SOURCES})

find_package(OpenSSL REQUIRED)
message("-- wtt: Found openssl ${OPENSSL_VERSION}")

target_link_libraries(${EXTENSION_NAME}
PUBLIC
"${CMAKE_CURRENT_BINARY_DIR}/Release/rust.lib"
ntdll
Secur32
OpenSSL::SSL
OpenSSL::Crypto
bcrypt
ncrypt
Userenv)


install(
TARGETS ${EXTENSION_NAME}
EXPORT "${DUCKDB_EXPORT_SET}"
LIBRARY DESTINATION "${INSTALL_LIB_DIR}"
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}")
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
pull:
git submodule init
git submodule update --recursive --remote


MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
PROJ_DIR := $(dir $(MKFILE_PATH))

OSX_BUILD_UNIVERSAL_FLAG=
ifeq (${OSX_BUILD_UNIVERSAL}, 1)
OSX_BUILD_UNIVERSAL_FLAG=-DOSX_BUILD_UNIVERSAL=1
endif
ifeq (${STATIC_LIBCPP}, 1)
STATIC_LIBCPP=-DSTATIC_LIBCPP=TRUE
endif

ifeq ($(GEN),ninja)
GENERATOR=-G "Ninja"
FORCE_COLOR=-DFORCE_COLORED_OUTPUT=1
endif

BUILD_FLAGS=-DEXTENSION_STATIC_BUILD=1 ${OSX_BUILD_UNIVERSAL_FLAG} ${STATIC_LIBCPP}
ifeq (${BUILD_SHELL}, 0)
BUILD_FLAGS += -DBUILD_SHELL=0
endif

CLIENT_FLAGS :=

# These flags will make DuckDB build the extension
EXTENSION_FLAGS=-DENABLE_SANITIZER=OFF -DDUCKDB_OOT_EXTENSION_NAMES="exon" -DDUCKDB_OOT_EXTENSION_EXON_PATH="$(PROJ_DIR)" -DDUCKDB_OOT_EXTENSION_EXON_SHOULD_LINK="TRUE" -DDUCKDB_OOT_EXTENSION_EXON_INCLUDE_PATH="$(PROJ_DIR)exon/include"

release:
mkdir -p build/release && \
cmake $(GENERATOR) $(FORCE_COLOR) $(EXTENSION_FLAGS) ${CLIENT_FLAGS} -DEXTENSION_STATIC_BUILD=1 -DCMAKE_BUILD_TYPE=Release ${BUILD_FLAGS} -S ./duckdb/ -B build/release && \
cmake --build build/release --config Release
1 change: 1 addition & 0 deletions duckdb
Submodule duckdb added at 9d5158
34 changes: 34 additions & 0 deletions exon/include/exon/sam_functions/module.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2023 WHERE TRUE Technologies.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <duckdb.hpp>
#include <duckdb/parser/parsed_data/create_scalar_function_info.hpp>
#include <duckdb/parser/parsed_data/create_table_function_info.hpp>
#include <duckdb/parser/parsed_data/create_copy_function_info.hpp>
#include <duckdb/parser/tableref/table_function_ref.hpp>

namespace exon
{

class SamFunctions
{
public:
static duckdb::unique_ptr<duckdb::CreateScalarFunctionInfo> GetParseCIGARStringFunction();
static duckdb::unique_ptr<duckdb::CreateScalarFunctionInfo> GetExtractFromCIGARFunction();
static std::vector<duckdb::unique_ptr<duckdb::CreateScalarFunctionInfo>> GetSamFunctions();
};

} // namespace wtt01
13 changes: 13 additions & 0 deletions exon/include/exon_extension.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include "duckdb.hpp"

namespace duckdb {

class ExonExtension : public Extension {
public:
void Load(DuckDB &db) override;
std::string Name() override;
};

} // namespace duckdb
65 changes: 65 additions & 0 deletions exon/include/rust.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <ostream>
#include <new>

struct ReaderResult {
const char *error;
};

struct ReplacementScanResult {
const char *file_type;
};

struct CResult {
const char *value;
const char *error;
};

struct CExtractResponse {
uintptr_t sequence_start;
uintptr_t sequence_len;
const char *extracted_sequence;
const char *error;
};

extern "C" {

ReaderResult new_reader(ArrowArrayStream *stream_ptr,
const char *uri,
uintptr_t batch_size,
const char *compression,
const char *file_format);

ReplacementScanResult replacement_scan(const char *uri);

bool is_segmented(uint16_t flag);

bool is_unmapped(uint16_t flag);

bool is_properly_aligned(uint16_t flag);

bool is_mate_unmapped(uint16_t flag);

bool is_reverse_complemented(uint16_t flag);

bool is_mate_reverse_complemented(uint16_t flag);

bool is_first_segment(uint16_t flag);

bool is_last_segment(uint16_t flag);

bool is_secondary(uint16_t flag);

bool is_quality_control_failed(uint16_t flag);

bool is_duplicate(uint16_t flag);

bool is_supplementary(uint16_t flag);

CResult parse_cigar(const char *cigar);

CExtractResponse extract_from_cigar(const char *sequence_str, const char *cigar_str);

} // extern "C"
5 changes: 5 additions & 0 deletions exon/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
add_subdirectory(exon)

set(EXTENSION_SOURCES
${EXTENSION_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/exon_extension.cpp
PARENT_SCOPE)
6 changes: 6 additions & 0 deletions exon/src/exon/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
add_subdirectory(sam_functions)

set(EXTENSION_SOURCES
${EXTENSION_SOURCES}
PARENT_SCOPE
)
5 changes: 5 additions & 0 deletions exon/src/exon/sam_functions/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set(EXTENSION_SOURCES
${EXTENSION_SOURCES}
${CMAKE_CURRENT_SOURCE_DIR}/module.cpp
PARENT_SCOPE
)
Loading

0 comments on commit 49ac97a

Please sign in to comment.