-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: usamoi <[email protected]>
- Loading branch information
Showing
6 changed files
with
152 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |