This commit is contained in:
Arthur Petukhovsky
2023-05-31 15:06:26 +00:00
parent b6a80bc269
commit 7b5123edda
5 changed files with 21 additions and 38 deletions

View File

@@ -0,0 +1,2 @@
*.a
*.o

View File

@@ -25,7 +25,6 @@ fn main() -> anyhow::Result<()> {
// println!("cargo:rustc-link-lib=pgport_srv");
println!("cargo:rustc-link-arg=-Wl,--start-group");
println!("cargo:rustc-link-arg=-lwalproposer");
println!("cargo:rustc-link-arg=-lext");
println!("cargo:rustc-link-arg=-lpgport_srv");
println!("cargo:rustc-link-arg=-lpostgres");
println!("cargo:rustc-link-arg=-lpgcommon_srv");
@@ -52,15 +51,15 @@ fn main() -> anyhow::Result<()> {
// disable fPIE
println!("cargo:rustc-link-arg=-no-pie");
// if !std::process::Command::new("./build.sh")
// .output()
// .expect("could not spawn `clang`")
// .status
// .success()
// {
// // Panic if the command was not successful.
// panic!("could not compile object file");
// }
if !std::process::Command::new("./build.sh")
.output()
.expect("could not spawn `clang`")
.status
.success()
{
// Panic if the command was not successful.
panic!("could not compile object file");
}
// println!("cargo:rustc-link-lib=dylib=neon");
// println!("cargo:rustc-link-search=/Users/arthur/zen/zenith/pg_install/build/neon-v15");

View File

@@ -1,32 +1,15 @@
#!/bin/bash
set -e
# cc -c -o walproposer.o \
# -static \
# -I /Users/arthur/zen/zenith/pg_install/v15/include/postgresql/server \
# /Users/arthur/zen/zenith/pgxn/neon/walproposer.c
# TODO: rewrite to Makefile
# cc -shared \
# -I /Users/arthur/zen/zenith/pg_install/v15/include/postgresql/server \
# -I /Users/arthur/zen/zenith/pgxn/neon \
# -L /Users/arthur/zen/zenith/pg_install/build/v15/src/common \
# -L /Users/arthur/zen/zenith/pg_install/build/v15/src/port \
# -lpgcommon -lpgport -lz -lreadline -lm \
# -o walproposer.so walproposer.o
# clang -c -o walproposer.o walproposer.c -ferror-limit=1
# ar rcs libwalproposer.a walproposer.o
make -C ../../ neon-pg-ext-v15 -s
make -C ../../pg_install/build/v15/src/backend postgres-lib -s
# make -C ../../ neon-pg-ext-v15 -s
# make -C ../../pg_install/build/v15/src/backend postgres-lib -s
cp ../../pg_install/build/v15/src/backend/libpostgres.a .
cp ../../pg_install/build/v15/src/common/libpgcommon_srv.a .
cp ../../pg_install/build/v15/src/port/libpgport_srv.a .
cp ../../pg_install/build/v15/src/interfaces/libpq/libpq.a .
# -lseccomp -lssl -lcrypto -lz -lpthread -lrt -ldl -lm
clang -c -o test.o test.c -ferror-limit=1 -I ../../pg_install/v15/include/postgresql/server
clang -g -c -o test.o test.c -ferror-limit=1 -I ../../pg_install/v15/include/postgresql/server
rm -rf libwalproposer.a
ar rcs libwalproposer.a test.o

View File

@@ -1,3 +0,0 @@
int hohoho(int a, int b) {
return a + b;
}

View File

@@ -2,15 +2,17 @@
#include "rust_bindings.h"
#include <stdio.h>
#include "postgres.h"
#include "utils/memutils.h"
// From src/backend/main/main.c
const char *progname = "fakepostgres";
int hohoho(int a, int b);
int TestFunc(int a, int b) {
MemoryContextInit();
printf("TestFunc: %d + %d = %d\n", a, b, a + b);
// elog(LOG, "postgres elog test");
rust_function(0);
return hohoho(a, b);
elog(LOG, "postgres elog test");
printf("After rust_function\n");
return a + b;
}