Skip to content

Commit

Permalink
ci: remove cargo-pgrx in ci (#420)
Browse files Browse the repository at this point in the history
Signed-off-by: usamoi <[email protected]>
  • Loading branch information
usamoi authored Mar 13, 2024
1 parent afe2b65 commit 71e1815
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 14 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ jobs:
key: ${{ github.job }}-${{ matrix.version }}-${{ matrix.os }}-${{ hashFiles('./Cargo.lock') }}
- name: Set up PostgreSQL
run: ./scripts/ci_setup.sh
- name: Set up Pgrx
run: mkdir -p ~/.pgrx && echo "configs.pg$VERSION=\"$(which pg_config)\"" > ~/.pgrx/config.toml
- name: Set up Python
uses: actions/setup-python@v5
with:
Expand All @@ -77,13 +79,13 @@ jobs:
run: curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
- name: Set up Sqllogictest
run: cargo binstall sqllogictest-bin -y --force
- name: Set up Pgrx
run: |
cargo install cargo-pgrx@$(grep 'pgrx = {' Cargo.toml | cut -d '"' -f 2 | head -n 1) --debug
cargo pgrx init --pg$VERSION=$(which pg_config)
- name: Release build
run: |
cargo pgrx install --no-default-features --features "pg$VERSION" --release
cargo build --no-default-features --features "pg$VERSION" --release
./tools/schema.sh --no-default-features --features "pg$VERSION" --release | sudo tee "/usr/share/postgresql/$VERSION/extension/vectors--0.0.0.sql"
sed -e "s/@CARGO_VERSION@/0.0.0/g" < ./vectors.control | sudo tee "/usr/share/postgresql/$VERSION/extension/vectors.control"
cp ./target/release/libvectors.so "/usr/lib/postgresql/$VERSION/lib/vectors.so"
psql -c 'ALTER SYSTEM SET shared_preload_libraries = "vectors.so"'
psql -c 'ALTER SYSTEM SET search_path = "$user", public, vectors'
psql -c 'ALTER SYSTEM SET logging_collector = on'
Expand Down Expand Up @@ -130,12 +132,10 @@ jobs:
key: ${{ github.job }}-${{ matrix.version }}-${{ matrix.os }}-${{ hashFiles('./Cargo.lock') }}
- name: Set up PostgreSQL
run: ./scripts/ci_setup.sh
- name: Set up Pgrx
run: mkdir -p ~/.pgrx && echo "configs.pg$VERSION=\"$(which pg_config)\"" > ~/.pgrx/config.toml
- name: Set up Binstall
run: curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
- name: Set up Pgrx
run: |
cargo install cargo-pgrx@$(grep 'pgrx = {' Cargo.toml | cut -d '"' -f 2 | head -n 1) --debug
cargo pgrx init --pg$VERSION=$(which pg_config)
- name: Semantic check
run: |
cargo clippy --no-default-features --features "pg${{ matrix.version }}" --target x86_64-unknown-linux-gnu
Expand Down
3 changes: 2 additions & 1 deletion scripts/build_0.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get install -y --no-install-recomm
wget \
xsltproc \
zlib1g-dev \
zip
zip \
qemu-user-static
apt-get install -y --no-install-recommends sudo ca-certificates

echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" | sudo tee -a /etc/apt/sources.list.d/pgdg.list
Expand Down
4 changes: 2 additions & 2 deletions scripts/build_2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ printf "ARCH = ${ARCH}\n"

export PLATFORM=$(echo $ARCH | sed 's/aarch64/arm64/; s/x86_64/amd64/')

cargo build --release --no-default-features --features pg$VERSION --target ${ARCH}-unknown-linux-gnu
cargo pgrx schema --no-default-features --features pg$VERSION | expand -t 4 > ./target/vectors--$SEMVER.sql
cargo build --no-default-features --features pg$VERSION --release --target ${ARCH}-unknown-linux-gnu
./tools/schema.sh --no-default-features --features pg$VERSION --release --target ${ARCH}-unknown-linux-gnu | expand -t 4 > ./target/vectors--$SEMVER.sql

rm -rf ./build/dir_zip
rm -rf ./build/vectors-pg${VERSION}_${ARCH}-unknown-linux-gnu_${SEMVER}.zip
Expand Down
16 changes: 14 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,20 @@ unsafe extern "C" fn _PG_init() {
}
}

#[cfg(not(all(target_endian = "little", target_pointer_width = "64")))]
compile_error!("Target is not supported.");

#[global_allocator]
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;

#[cfg(not(all(target_endian = "little", target_pointer_width = "64")))]
compile_error!("Target is not supported.");
#[no_mangle]
unsafe extern "Rust" fn _vectors_jemalloc_alloc(layout: std::alloc::Layout) -> *mut u8 {
use std::alloc::GlobalAlloc;
unsafe { GLOBAL.alloc(layout) }
}

#[no_mangle]
unsafe extern "Rust" fn _vectors_jemalloc_dealloc(ptr: *mut u8, layout: std::alloc::Layout) {
use std::alloc::GlobalAlloc;
unsafe { GLOBAL.dealloc(ptr, layout) }
}
78 changes: 78 additions & 0 deletions tools/schema-codegen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env bash
set -e

# CONTROL_FILEPATH
# SO_FILEPATH

cat << EOF
extern "Rust" {
fn _vectors_jemalloc_alloc(layout: std::alloc::Layout) -> *mut u8;
fn _vectors_jemalloc_dealloc(ptr: *mut u8, layout: std::alloc::Layout);
}
struct Jemalloc;
unsafe impl std::alloc::GlobalAlloc for Jemalloc {
unsafe fn alloc(&self, layout: std::alloc::Layout) -> *mut u8 {
unsafe { _vectors_jemalloc_alloc(layout) }
}
unsafe fn dealloc(&self, ptr: *mut u8, layout: std::alloc::Layout) {
unsafe { _vectors_jemalloc_dealloc(ptr, layout) }
}
}
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;
EOF

while read -r sym; do
if [ "$sym" = "__gmon_start__" ]; then
continue
fi
cat << EOF
#[no_mangle]
extern "C" fn $sym() {
eprintln!("Calling undefined symbol: {}", "$sym");
std::process::exit(1);
}
EOF
done <<< $(nm -u $SO_FILEPATH | grep -v "@" | awk '{print $2}')

printf "fn main() {\n"

cat << EOF
// vectors::__pgrx_marker();
let mut entities = Vec::new();
let control_file_path = std::path::PathBuf::from("$CONTROL_FILEPATH");
let control_file = ::pgrx::pgrx_sql_entity_graph::ControlFile::try_from(control_file_path).expect(".control file should properly formatted");
let control_file_entity = ::pgrx::pgrx_sql_entity_graph::SqlGraphEntity::ExtensionRoot(control_file);
entities.push(control_file_entity);
EOF

while read -r name_ident; do
cat << EOF
extern "Rust" {
fn $name_ident() -> ::pgrx::pgrx_sql_entity_graph::SqlGraphEntity;
}
let entity = unsafe { $name_ident() };
entities.push(entity);
EOF
done <<< $(nm -D -g $SO_FILEPATH | grep "T __pgrx_internals_" | awk '{print $3}')

cat << EOF
let pgrx_sql = ::pgrx::pgrx_sql_entity_graph::PgrxSql::build(
entities.into_iter(),
"vectors".to_string(),
false,
)
.expect("SQL generation error");
eprintln!("SQL entities to {}", "/dev/stdout",);
pgrx_sql
.write(&mut std::io::stdout())
.expect("Could not write SQL to stdout");
EOF

printf "}\n"
47 changes: 47 additions & 0 deletions tools/schema.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
set -e

if [[ " $@ " =~ --target' '([^ ]+) ]]; then
TARGET="${BASH_REMATCH[1]}"
if [[ " $@ " =~ " --release " ]]; then
DIR="./target/$TARGET/release"
else
DIR="./target/$TARGET/debug"
fi
else
TARGET=""
if [[ " $@ " =~ " --release " ]]; then
DIR="./target/release"
else
DIR="./target/debug"
fi
fi

if [ "$TARGET" = "" ]; then
printf "Target: [not specified]\n" 1>&2
RUNNER=()
elif [ "$TARGET" = $(rustc -vV | awk '/^host/ { print $2 }') ]; then
printf "Target: [host]\n" 1>&2
RUNNER=()
elif [ "$TARGET" = "aarch64-unknown-linux-gnu" ]; then
printf "Target: $TARGET\n" 1>&2
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/aarch64-linux-gnu/lib:/usr/aarch64-linux-gnu/lib64"
QEMU_LD_PREFIX="/usr/aarch64-linux-gnu"
RUNNER=("qemu-aarch64-static")
elif [ "$TARGET" = "riscv64gc-unknown-linux-gnu" ]; then
printf "Target: $TARGET\n" 1>&2
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/riscv64-linux-gnu/lib"
QEMU_LD_PREFIX="/usr/riscv64-linux-gnu"
RUNNER=("qemu-riscv64-static")
else
printf "Unknown target: $TARGET\n" 1>&2
exit 1
fi

code=$(mktemp)
chmod 700 $code
CONTROL_FILEPATH="./vectors.control" SO_FILEPATH="$DIR/libvectors.so" $(dirname "$0")/schema-codegen.sh >> $code

PGRX_EMBED=$code cargo rustc --bin pgrx_embed_vectors "$@" -- --cfg pgrx_embed -Clink-args="-L$DIR -lvectors"

CARGO_PKG_VERSION="0.0.0" LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$DIR QEMU_LD_PREFIX=$QEMU_LD_PREFIX "${RUNNER[@]}" "$DIR/pgrx_embed_vectors" | expand -t 4

0 comments on commit 71e1815

Please sign in to comment.