fix: rust build

This commit is contained in:
Didier Franc
2025-04-09 21:45:15 +02:00
parent fd21d0ed80
commit 6b28c0e4ac
3 changed files with 100 additions and 14 deletions

View File

@@ -1,6 +1,17 @@
use std::path::PathBuf;
fn main() {
let target_triple = std::env::consts::ARCH.to_string() + "-apple-" + "darwin";
let current_dir = std::env::current_dir().expect("Failed to get current directory");
let new_name = format!("libchdb.so-{}", target_triple);
let source = current_dir.join("libchdb.so");
let dest = current_dir.join(&new_name);
if source.exists() && !dest.exists() {
std::fs::rename(source, dest).expect("Failed to rename library file");
}
tauri_build::build();
// // Tell cargo to look for shared libraries in the specified directory
@@ -18,8 +29,7 @@ fn main() {
let bindings = bindgen::Builder::default()
// The input header we would like to generate
// bindings for.
.header("chdb.h")
// Tell cargo to invalidate the built crate whenever any of the
.header("chdb.h") // Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
// Finish the builder and generate the bindings.

View File

@@ -21,6 +21,7 @@ pub const _DARWIN_FEATURE_ONLY_VERS_1050: u32 = 1;
pub const _DARWIN_FEATURE_ONLY_UNIX_CONFORMANCE: u32 = 1;
pub const _DARWIN_FEATURE_UNIX_CONFORMANCE: u32 = 3;
pub const __has_ptrcheck: u32 = 0;
pub const __has_bounds_safety_attributes: u32 = 0;
pub const USE_CLANG_TYPES: u32 = 0;
pub const __PTHREAD_SIZE__: u32 = 8176;
pub const __PTHREAD_ATTR_SIZE__: u32 = 56;

View File

@@ -1,12 +1,38 @@
#!/bin/bash
set -e
cd $(dirname "${BASH_SOURCE[0]}")
# Check for necessary tools
command -v curl >/dev/null 2>&1 || { echo >&2 "curl is required but it's not installed. Aborting."; exit 1; }
command -v tar >/dev/null 2>&1 || { echo >&2 "tar is required but it's not installed. Aborting."; exit 1; }
# Function to download and extract the file
download_and_extract() {
local url=$1
local file="src-tauri/libchdb.tar.gz"
echo "Attempting to download $PLATFORM from $url"
# Download the file with a retry logic
if curl -L -o "$file" "$url"; then
echo "Download successful."
if tar -xzf "$file" -C ./src-tauri; then
echo "Extraction successful."
echo "Remove the downloaded archive"
rm -f "$file"
return 0
fi
fi
return 1
}
# Get the newest release version
#LATEST_RELEASE=$(curl --silent "https://api.github.com/repos/chdb-io/chdb/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
LATEST_RELEASE=v2.1.1
# Download the correct version based on the platform
# Select the correct package based on OS and architecture
case "$(uname -s)" in
Linux)
if [[ $(uname -m) == "aarch64" ]]; then
@@ -28,18 +54,67 @@ case "$(uname -s)" in
;;
esac
# Main download URL
DOWNLOAD_URL="https://github.com/chdb-io/chdb/releases/download/$LATEST_RELEASE/$PLATFORM"
FALLBACK_URL="https://github.com/chdb-io/chdb/releases/latest/download/$PLATFORM"
echo "Downloading $PLATFORM from $DOWNLOAD_URL"
# Try the main download URL first
if ! download_and_extract "$DOWNLOAD_URL"; then
echo "Retrying with fallback URL..."
if ! download_and_extract "$FALLBACK_URL"; then
echo "Both primary and fallback downloads failed. Aborting."
exit 1
fi
fi
# Download the file
curl -L -o libchdb.tar.gz $DOWNLOAD_URL
chmod +x src-tauri/libchdb.so
# Untar the file
tar -xzf libchdb.tar.gz
if [[ "$1" == "--global" ]]; then
# If current uid is not 0, check if sudo is available and request the user to input the password
if [[ $EUID -ne 0 ]]; then
command -v sudo >/dev/null 2>&1 || { echo >&2 "This script requires sudo privileges but sudo is not installed. Aborting."; exit 1; }
echo "Installation requires administrative access. You will be prompted for your password."
fi
# Set execute permission for libchdb.so
chmod +x libchdb.so
# Define color messages if terminal supports them
if [[ -t 1 ]]; then
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
REDECHO() { echo -e "${RED}$@${NC}"; }
GREENECHO() { echo -e "${GREEN}$@${NC}"; }
ENDECHO() { echo -ne "${NC}"; }
else
REDECHO() { echo "$@"; }
GREENECHO() { echo "$@"; }
ENDECHO() { :; }
fi
# Clean up
rm -f libchdb.tar.gz
# Use sudo if not running as root
SUDO=''
if [[ $EUID -ne 0 ]]; then
SUDO='sudo'
GREENECHO "\nYou will be asked for your sudo password to install:"
echo " libchdb.so to /usr/local/lib/"
echo " chdb.h to /usr/local/include/"
fi
# Make sure the library and header directory exists
${SUDO} mkdir -p /usr/local/lib /usr/local/include || true
# Install the library and header file
${SUDO} /bin/cp src-tauri/libchdb.so /usr/local/lib/
${SUDO} /bin/cp src-tauri/chdb.h /usr/local/include/
# Set execute permission for libchdb.so
${SUDO} chmod +x /usr/local/lib/libchdb.so
# Update library cache (Linux specific)
if [[ "$(uname -s)" == "Linux" ]]; then
${SUDO} ldconfig
fi
GREENECHO "Installation completed successfully." ; ENDECHO
GREENECHO "If any error occurred, please report it to:" ; ENDECHO
GREENECHO " https://github.com/chdb-io/chdb/issues/new/choose" ; ENDECHO
fi