Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9a76676

Browse files
committed
Refactor update_libchdb.sh for system-wide install and improve README documentation
1 parent35d4223 commit9a76676

File tree

5 files changed

+126
-19
lines changed

5 files changed

+126
-19
lines changed

‎.gitignore‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Cargo.lock
33
*.tar.gz
44
*.so
5-
*.h
5+
chdb.h
66
var
77
udf
88
*.parquet

‎README.md‎

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,42 @@
33
[![Rust](https://github.com/chdb-io/chdb-rust/actions/workflows/rust.yml/badge.svg)](https://github.com/chdb-io/chdb-rust/actions/workflows/rust.yml)
44

55
#chdb-rust <imgsrc="https://upload.wikimedia.org/wikipedia/commons/thumb/d/d5/Rust_programming_language_black_logo.svg/1024px-Rust_programming_language_black_logo.svg.png"height=20 />
6+
67
Experimental[chDB](https://github.com/chdb-io/chdb) FFI bindings for Rust
78

8-
###Status
9+
##Status
910

1011
- Experimental, unstable, subject to changes
11-
- Requires[`libchdb`](https://github.com/chdb-io/chdb) on the system
12+
- Requires[`libchdb`](https://github.com/chdb-io/chdb) on the system. You can install the compatible version from
13+
`install_libchdb.sh`
14+
15+
##Usage
16+
17+
###Install libchdb
18+
19+
You can install it system-wide
20+
21+
```bash
22+
./update_libchdb.sh --global
23+
```
24+
25+
or use it in a local directory
26+
27+
```bash
28+
./update_libchdb.sh --local
29+
```
30+
31+
###Build
1232

13-
####Build binding
1433
```bash
15-
./update_libchdb.sh
1634
RUST_BACKTRACE=full cargo build --verbose
35+
1736
```
1837

1938
###Run tests
39+
2040
`cargo test`
2141

2242
###Examples
43+
2344
See`tests` directory.

‎build.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn main() {
1616
let bindings = bindgen::Builder::default()
1717
// The input header we would like to generate
1818
// bindings for.
19-
.header("chdb.h")
19+
.header("wrapper.h")
2020
// Tell cargo to invalidate the built crate whenever any of the
2121
// included header files changed.
2222
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))

‎update_libchdb.sh‎

Lines changed: 98 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,37 @@
1-
21
#!/bin/bash
2+
33
set -e
4-
cd$(dirname"${BASH_SOURCE[0]}")
4+
5+
# Check for necessary tools
6+
command -v curl>/dev/null2>&1|| {echo>&2"curl is required but it's not installed. Aborting.";exit 1; }
7+
command -v tar>/dev/null2>&1|| {echo>&2"tar is required but it's not installed. Aborting.";exit 1; }
8+
9+
# Function to download and extract the file
10+
download_and_extract() {
11+
local url=$1
12+
local file="libchdb.tar.gz"
13+
14+
echo"Attempting to download$PLATFORM from$url"
15+
16+
# Download the file with a retry logic
17+
if curl -L -o"$file""$url";then
18+
echo"Download successful."
19+
20+
# Optional: Verify download integrity here, if checksums are provided
21+
22+
# Untar the file
23+
if tar -xzf"$file";then
24+
echo"Extraction successful."
25+
return 0
26+
fi
27+
fi
28+
return 1
29+
}
530

631
# Get the newest release version
7-
# LATEST_RELEASE=$(curl --silent "https://api.github.com/repos/chdb-io/chdb/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
832
LATEST_RELEASE=v2.1.1
933

10-
#Download the correctversion based onthe platform
34+
#Select the correctpackage based onOS and architecture
1135
case"$(uname -s)"in
1236
Linux)
1337
if [[$(uname -m)=="aarch64" ]];then
@@ -29,18 +53,79 @@ case "$(uname -s)" in
2953
;;
3054
esac
3155

56+
# Main download URL
3257
DOWNLOAD_URL="https://github.com/chdb-io/chdb/releases/download/$LATEST_RELEASE/$PLATFORM"
58+
FALLBACK_URL="https://github.com/chdb-io/chdb/releases/latest/download/$PLATFORM"
59+
60+
# Try the main download URL first
61+
if! download_and_extract"$DOWNLOAD_URL";then
62+
echo"Retrying with fallback URL..."
63+
if! download_and_extract"$FALLBACK_URL";then
64+
echo"Both primary and fallback downloads failed. Aborting."
65+
exit 1
66+
fi
67+
fi
68+
69+
# check if --local flag is passed
70+
if [["$1"=="--local" ]];then
71+
# Set execute permission for libchdb.so
72+
chmod +x libchdb.so
73+
74+
# Clean up
75+
rm -f libchdb.tar.gz
76+
exit 0
77+
elif [["$1"=="--global" ]];then
78+
# If current uid is not 0, check if sudo is available and request the user to input the password
79+
if [[$EUID-ne 0 ]];then
80+
command -v sudo>/dev/null2>&1|| {echo>&2"This script requires sudo privileges but sudo is not installed. Aborting.";exit 1; }
81+
echo"Installation requires administrative access. You will be prompted for your password."
82+
fi
83+
84+
# Define color messages if terminal supports them
85+
if [[-t 1 ]];then
86+
RED='\033[0;31m'
87+
GREEN='\033[0;32m'
88+
NC='\033[0m'# No Color
89+
REDECHO() {echo -e"${RED}$@${NC}"; }
90+
GREENECHO() {echo -e"${GREEN}$@${NC}"; }
91+
ENDECHO() {echo -ne"${NC}"; }
92+
else
93+
REDECHO() {echo"$@"; }
94+
GREENECHO() {echo"$@"; }
95+
ENDECHO() {:; }
96+
fi
97+
98+
# Use sudo if not running as root
99+
SUDO=''
100+
if [[$EUID-ne 0 ]];then
101+
SUDO='sudo'
102+
GREENECHO"\nYou will be asked for your sudo password to install:"
103+
echo" libchdb.so to /usr/local/lib/"
104+
echo" chdb.h to /usr/local/include/"
105+
fi
106+
107+
# Make sure the library and header directory exists
108+
${SUDO} mkdir -p /usr/local/lib /usr/local/include||true
33109

34-
echo"Downloading$PLATFORM from$DOWNLOAD_URL"
110+
# Install the library and header file
111+
${SUDO} /bin/cp libchdb.so /usr/local/lib/
112+
${SUDO} /bin/cp chdb.h /usr/local/include/
35113

36-
# Download the file
37-
curl -L -olibchdb.tar.gz$DOWNLOAD_URL
114+
# Set execute permission for libchdb.so
115+
${SUDO} chmod +x /usr/local/lib/libchdb.so
38116

39-
# Untar the file
40-
tar -xzf libchdb.tar.gz
117+
# Update library cache (Linux specific)
118+
if [["$(uname -s)"=="Linux" ]];then
119+
${SUDO} ldconfig
120+
fi
41121

42-
# Set execute permission for libchdb.so
43-
chmod +xlibchdb.so
122+
# Clean up
123+
rm -flibchdb.tar.gz libchdb.so chdb.h
44124

45-
# Clean up
46-
rm -f libchdb.tar.gz
125+
GREENECHO"Installation completed successfully."; ENDECHO
126+
GREENECHO"If any error occurred, please report it to:"; ENDECHO
127+
GREENECHO" https://github.com/chdb-io/chdb/issues/new/choose"; ENDECHO
128+
else
129+
echo"Invalid option. Use --local to install locally or --global to install globally."
130+
exit 1
131+
fi

‎wrapper.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include"chdb.h"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp