Skip to content

Instantly share code, notes, and snippets.

@Swoorup
Created December 19, 2022 09:49
Show Gist options
  • Save Swoorup/d4eb8ddd5f409ae4fadf32df7825fa2f to your computer and use it in GitHub Desktop.
Save Swoorup/d4eb8ddd5f409ae4fadf32df7825fa2f to your computer and use it in GitHub Desktop.
duckdb shared library helper for cargo-make
[config]
# skip_core_tasks = true
# skip_git_env_info = true
# skip_crate_env_info = true
# skip_rust_env_info = true
[env]
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true
SHARED_LIB_DIR = "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/shared_lib"
LIBRARY_EXTENSION = { source = "${CARGO_MAKE_RUST_TARGET_OS}", default_value = "unknown", mapping = {"linux" = "so", "macos" = "dylib" } }
LIB_DUCKDB_VER = "v0.6.0"
LIB_DUCKDB_ZIP_FILENAME = { source = "${CARGO_MAKE_RUST_TARGET_OS}", default_value = "unknown", mapping = {"linux" = "libduckdb-linux-amd64.zip", "macos" = "libduckdb-osx-universal.zip" }}
LIB_DUCKDB_LIB_FILENAME = "libduckdb.${LIBRARY_EXTENSION}"
LIB_DUCKDB_ZIP_URL = "https://github.com/duckdb/duckdb/releases/download/${LIB_DUCKDB_VER}/${LIB_DUCKDB_ZIP_FILENAME}"
[tasks.test]
command = "cargo"
args = ["test"]
env = { "RUST_BACKTRACE" = true }
dependencies = ["shared_deps"]
[tasks."watch.test"]
watch = true
dependencies = ["test"]
[tasks."shared_deps"]
dependencies = ["shared_deps.setup"]
[tasks."shared_deps.setup"]
workspace = false
dependencies = ["shared_deps.download"]
condition.files_not_exist = [ "${CARGO_MAKE_CRATE_TARGET_DIRECTORY}/debug/deps/${LIB_DUCKDB_LIB_FILENAME}" ]
condition.fail_message = "Shared deps is already setup for dev."
script = '''
#!@duckscript
mkdir ${CARGO_MAKE_CRATE_TARGET_DIRECTORY}/debug
mkdir ${CARGO_MAKE_CRATE_TARGET_DIRECTORY}/release
cd ${SHARED_LIB_DIR}
echo Copying shared library to target
count = glob_cp ./*.${LIBRARY_EXTENSION} ${CARGO_MAKE_CRATE_TARGET_DIRECTORY}/debug/deps
echo Copied ${count} file(s) to debug target directory
count = glob_cp ./*.${LIBRARY_EXTENSION} ${CARGO_MAKE_CRATE_TARGET_DIRECTORY}/release/deps
echo Copied ${count} file(s) to release target directory
echo Setting up environment variables...
libduckdb_path = canonicalize ${SHARED_LIB_DIR}
set_env DUCKDB_LIB_DIR ${libduckdb_path}
set_env DUCKDB_INCLUDE_DIR ${libduckdb_path}
'''
[tasks."shared_deps.download"]
workspace = false
condition.files_not_exist = ["${SHARED_LIB_DIR}/${LIB_DUCKDB_ZIP_FILENAME}"]
condition.fail_message = "Already downloaded"
script = '''
echo Downloading duckdb from ${LIB_DUCKDB_ZIP_URL}
mkdir ${SHARED_LIB_DIR}
cd ${SHARED_LIB_DIR}
wget ${LIB_DUCKDB_ZIP_URL} -O ${LIB_DUCKDB_ZIP_FILENAME}
unzip ${LIB_DUCKDB_ZIP_FILENAME}
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment