Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FreeBSD support #210

Closed
rriski opened this issue Dec 27, 2023 · 6 comments
Closed

Add FreeBSD support #210

rriski opened this issue Dec 27, 2023 · 6 comments
Assignees

Comments

@rriski
Copy link

rriski commented Dec 27, 2023

What

Add FreeBSD support.

How

The required changes are detailed here in short and a patch is provided below. The patch definitely needs more work (e.g. I'm not sure if my futex_wake and futex_wake are correct, they are adapted from Rust source code). The patch is provided an example on how to get the project built on FreeBSD.

  • Allow overriding clang path or detect it here
    .compiler("/usr/bin/clang-16")
  • Add #![feature(... where the compiler complained about missing features
  • Add futex_wait, futex_wake functions for FreeBSD
  • Modify memfd_create and mmap_populate to support FreeBSD
FreeBSD patch

freebsd.patch.txt. futex_wake and futex_wake are adapted from information from this Rust issue on FreeBSD futex support rust-lang/rust#93740 (comment) and Rust source code.

root@test:/tmp/pgvecto.rs # git diff
diff --git a/crates/c/build.rs b/crates/c/build.rs
index dad6633..8ff08b9 100644
--- a/crates/c/build.rs
+++ b/crates/c/build.rs
@@ -2,7 +2,7 @@ fn main() {
     println!("cargo:rerun-if-changed=src/c.h");
     println!("cargo:rerun-if-changed=src/c.c");
     cc::Build::new()
-        .compiler("/usr/bin/clang-16")
+        .compiler("/usr/local/bin/clang16")
         .file("./src/c.c")
         .opt_level(3)
         .debug(true)
diff --git a/crates/service/src/lib.rs b/crates/service/src/lib.rs
index b534589..4f550d1 100644
--- a/crates/service/src/lib.rs
+++ b/crates/service/src/lib.rs
@@ -1,4 +1,5 @@
 #![feature(core_intrinsics)]
+#![feature(int_roundings)]
 #![feature(avx512_target_feature)]

 pub mod algorithms;
diff --git a/crates/service/src/prelude/scalar/mod.rs b/crates/service/src/prelude/scalar/mod.rs
index 1894a90..eedc5d8 100644
--- a/crates/service/src/prelude/scalar/mod.rs
+++ b/crates/service/src/prelude/scalar/mod.rs
@@ -2,4 +2,4 @@ mod f16;
 mod f32;

 pub use f16::F16;
-pub use f32::F32;
+pub use self::f32::F32;
diff --git a/src/lib.rs b/src/lib.rs
index cf69461..2267094 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -4,6 +4,8 @@
 #![feature(offset_of)]
 #![feature(arbitrary_self_types)]
 #![feature(try_blocks)]
+#![feature(strict_provenance)]
+#![feature(const_maybe_uninit_zeroed)]

 mod bgworker;
 mod datatype;
@@ -33,7 +35,7 @@ unsafe extern "C" fn _PG_init() {
     }
 }

-#[cfg(not(any(target_os = "linux", target_os = "macos")))]
+#[cfg(not(any(target_os = "linux", target_os = "macos", target_os="freebsd")))]
 compile_error!("Target is not supported.");

 #[cfg(not(target_endian = "little"))]
diff --git a/src/utils/os.rs b/src/utils/os.rs
index d77f718..6c34c80 100644
--- a/src/utils/os.rs
+++ b/src/utils/os.rs
@@ -19,6 +19,61 @@ pub unsafe fn futex_wait(futex: &AtomicU32, value: u32) {
     }
 }

+#[cfg(target_os = "freebsd")]
+pub fn futex_wake(futex: &AtomicU32) -> bool {
+    use std::ptr::null_mut;
+    unsafe {
+        libc::_umtx_op(
+            futex as *const AtomicU32 as *mut _,
+            libc::UMTX_OP_WAKE_PRIVATE,
+            1,
+            null_mut(),
+            null_mut(),
+        )
:
+    let timeout = 15;
+
+    loop {
+        // No need to wait if the value already changed.
+        if futex.load(Relaxed) != value {
+            return;
+        }
+
+        // Calculate the absolute timeout.
+        let mut ts = timespec {
+            tv_sec: timeout as libc::time_t,
+            tv_nsec: 0,
+        };
+        libc::clock_gettime(libc::CLOCK_MONOTONIC, &mut ts);
+        ts.tv_sec += timeout as libc::time_t;
+
+        // Prepare the umtx_time structure.
+        let umtx_timeout = libc::_umtx_time {
+            _timeout: ts,
+            _flags: UMTX_ABSTIME,
+            _clockid: libc::CLOCK_MONOTONIC as u32,
+        };
+
+        // Call _umtx_op.
+        libc::_umtx_op(
+            futex as *const AtomicU32 as *mut _,
+            UMTX_OP_WAIT_UINT_PRIVATE,
+            value as libc::c_ulong,
+            std::ptr::null_mut(),
+            &umtx_timeout as *const _ as *mut _,
+        );
+    }
+}
+
+#[cfg(target_os = "freebsd")]
+pub fn futex_wake(futex: &AtomicU32) -> bool {
+    use std::ptr::null_mut;
+    unsafe {
+        libc::_umtx_op(
+            futex as *const AtomicU32 as *mut _,
+            libc::UMTX_OP_WAKE_PRIVATE,
+            1,
+            null_mut(),
+            null_mut(),
+        )
+    };
+    false
+}
+
 #[cfg(target_os = "linux")]
 pub unsafe fn futex_wake(futex: &AtomicU32) {
     unsafe {
@@ -26,7 +81,7 @@ pub unsafe fn futex_wake(futex: &AtomicU32) {
     }
 }

-#[cfg(target_os = "linux")]
+#[cfg(any(target_os = "linux", target_os="freebsd"))]
 pub fn memfd_create() -> std::io::Result<OwnedFd> {
     use rustix::fs::MemfdFlags;
     Ok(rustix::fs::memfd_create(
@@ -35,7 +90,7 @@ pub fn memfd_create() -> std::io::Result<OwnedFd> {
     )?)
 }

-#[cfg(target_os = "linux")]
+#[cfg(any(target_os = "linux", target_os="freebsd"))]
 pub unsafe fn mmap_populate(len: usize, fd: impl AsFd) -> std::io::Result<*mut libc::c_void> {
     use std::ptr::null_mut;
     unsafe {
@@ -43,7 +98,7 @@ pub unsafe fn mmap_populate(len: usize, fd: impl AsFd) -> std::io::Result<*mut l
             null_mut(),
             len,
             ProtFlags::READ | ProtFlags::WRITE,
-            MapFlags::SHARED | MapFlags::POPULATE,
+            MapFlags::SHARED,
             fd,
             0,
         )?)
(END)

With the above changes cargo pgrx install --sudo --release succeeds but the post build scripts fail with libintl.h not found (Related pgrx issue pgcentralfoundation/pgrx#470):

fatal error: 'libintl.h' file not found
cargo pgrx package
       Using PgConfig("pg15") and `pg_config` from /usr/local/bin/pg_config
    Building extension with features pg15
     Running command "/usr/local/bin/cargo" "build" "--release" "--features" "pg15" "--no-default-features" "--message-format=json-render-diagnostics"
warning: /tmp/pgvecto.rs/Cargo.toml: unused manifest key `lints` (may be supported in a future version)

consider passing `-Zlints` to enable this feature.
warning: /tmp/pgvecto.rs/crates/service/Cargo.toml: unused manifest key `lints` (may be supported in a future version)

consider passing `-Zlints` to enable this feature.
   Compiling bindgen v0.68.1
   Compiling pgrx-pg-sys v0.11.0 (https://github.com/tensorchord/pgrx.git?rev=7c30e2023876c1efce613756f5ec81f3ab05696b#7c30e202)
error: failed to run custom build command for `pgrx-pg-sys v0.11.0 (https://github.com/tensorchord/pgrx.git?rev=7c30e2023876c1efce613756f5ec81f3ab05696b#7c30e202)`

Caused by:
  process didn't exit successfully: `/tmp/pgvecto.rs/target/release/build/pgrx-pg-sys-fcd1fc6e215bce49/build-script-build` (exit status: 1)
  --- stdout
  cargo:rerun-if-env-changed=PGRX_BUILD_VERBOSE
  cargo:rerun-if-env-changed=PGRX_PG_SYS_GENERATE_BINDINGS_FOR_RELEASE
  cargo:rustc-cfg=nightly
  cargo:rerun-if-env-changed=PGRX_PG_CONFIG_PATH
  cargo:rerun-if-env-changed=PGRX_PG_CONFIG_AS_ENV
  cargo:rerun-if-env-changed=LLVM_CONFIG_PATH
  cargo:rerun-if-env-changed=LIBCLANG_PATH
  cargo:rerun-if-env-changed=LIBCLANG_STATIC_PATH
  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS
  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_x86_64-unknown-freebsd
  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_x86_64_unknown_freebsd
  cargo:rerun-if-env-changed=PGRX_PG_SYS_GENERATE_BINDINGS_FOR_RELEASE
  cargo:rerun-if-changed=include
  cargo:rerun-if-changed=cshim
  cargo:rerun-if-changed=/root/.pgrx/config.toml
  cargo:rerun-if-env-changed=PGRX_TARGET_INFO_PATH_PG15_x86_64-unknown-freebsd
  cargo:rerun-if-env-changed=PGRX_TARGET_INFO_PATH_PG15
  cargo:rerun-if-env-changed=PGRX_BINDGEN_NO_DETECT_INCLUDES_x86_64-unknown-freebsd
  cargo:rerun-if-env-changed=PGRX_BINDGEN_NO_DETECT_INCLUDES
  cargo:rerun-if-env-changed=PGRX_INCLUDEDIR_SERVER_PG15_x86_64-unknown-freebsd
  cargo:rerun-if-env-changed=PGRX_INCLUDEDIR_SERVER_PG15
  cargo:rerun-if-env-changed=PGRX_INCLUDEDIR_SERVER_x86_64-unknown-freebsd
  cargo:rerun-if-env-changed=PGRX_INCLUDEDIR_SERVER

  --- stderr
  build_paths=BuildPaths { manifest_dir: "/root/.cargo/git/checkouts/pgrx-82d5ad52313f9598/7c30e20/pgrx-pg-sys", out_dir: "/tmp/pgvecto.rs/target/release/build/pgrx-pg-sys-61e7790fba72a9a1/out", src_dir: "/root/.cargo/git/checkouts/pgrx-82d5ad52313f9598/7c30e20/pgrx-pg-sys/src/include", shim_src: "/root/.cargo/git/checkouts/pgrx-82d5ad52313f9598/7c30e20/pgrx-pg-sys/cshim", shim_dst: "/tmp/pgvecto.rs/target/release/build/pgrx-pg-sys-61e7790fba72a9a1/out/cshim" }
  Generating bindings for pg15
  pg_config --configure CLANG = None
  Bindgen found clang version 16.0.6
  found libclang at /usr/local/llvm16/lib/libclang.so.16.0.6
  Found include dirs ["/usr/local/llvm16/lib/clang/16/include"]
  /usr/local/include/postgresql/server/c.h:75:10: fatal error: 'libintl.h' file not found
  Error: bindgen failed for pg15

  Caused by:
     0: Unable to generate bindings for pg15
     1: clang diagnosed error: /usr/local/include/postgresql/server/c.h:75:10: fatal error: 'libintl.h' file not found


  Location:
      /root/.cargo/git/checkouts/pgrx-82d5ad52313f9598/7c30e20/pgrx-pg-sys/build.rs:742:10

The extension can be installed by manually copying the build artifacts from target/ with:

cp target/release/vectors-pg15/usr/local/lib/postgresql/vectors.so /usr/local/lib/postgresql/vectors.so
cp target/release/vectors-pg15/usr/local/share/postgresql/extension/vectors* /usr/local/share/postgresql/extension/
psql -U postgres -c 'ALTER SYSTEM SET shared_preload_libraries = "vectors.so"'
service postgresql status

After that the extension can be tested using the Get started instructions provided in this repo.

@rriski rriski changed the title Support FreeBSD Add FreeBSD support Dec 27, 2023
@gaocegege
Copy link
Member

Thanks for raising this!

cc @VoVAllen

@VoVAllen
Copy link
Member

VoVAllen commented Dec 28, 2023

Added FreeBSD support in #203 (83e00e2). However we don't have FreeBSD environment to test it now. Probably will include the related test in the future

@rriski
Copy link
Author

rriski commented Jan 5, 2024

Thanks! I'm still seeing errors related to "use of unstable library feature" and "f32 is ambiguous":

[root@test /tmp/pgvecto.rs]# cargo pgrx install --sudo --release
       Using PgConfig("pg15") and `pg_config` from /usr/local/bin/pg_config
    Building extension with features pg15
     Running command "/usr/local/bin/cargo" "build" "--release" "--features" "pg15" "--no-default-features" "--message-format=json-render-diagnostics"
warning: /tmp/pgvecto.rs/Cargo.toml: unused manifest key `lints` (may be supported in a future version)

consider passing `-Zlints` to enable this feature.
warning: /tmp/pgvecto.rs/crates/service/Cargo.toml: unused manifest key `lints` (may be supported in a future version)

consider passing `-Zlints` to enable this feature.
   Compiling serde_spanned v0.6.5
   Compiling toml_datetime v0.6.5
   Compiling pest v2.7.5
   Compiling serde_json v1.0.108
   Compiling pgrx-sql-entity-graph v0.11.2
   Compiling c v0.0.0 (/tmp/pgvecto.rs/crates/c)
   Compiling multiversion-macros v0.7.3
   Compiling pgrx-macros v0.11.2
   Compiling toml_edit v0.21.0
   Compiling rayon-core v1.12.0
   Compiling hash32 v0.2.1
   Compiling semver-parser v0.10.2
   Compiling crossbeam-channel v0.5.10
   Compiling crossbeam-queue v0.3.10
   Compiling uuid v1.6.1
   Compiling semver v0.11.0
   Compiling toml v0.8.8
   Compiling rustc_version v0.3.3
   Compiling ctor v0.2.6
   Compiling enum-map-derive v0.17.0
   Compiling winnow v0.5.31
   Compiling serde_cbor v0.11.2
   Compiling atomic-traits v0.3.0
   Compiling cargo_toml v0.16.3
   Compiling detect v0.0.0 (/tmp/pgvecto.rs/crates/detect)
   Compiling enum-map v2.7.3
   Compiling rayon v1.8.0
   Compiling ureq v2.9.1
   Compiling heapless v0.7.17
   Compiling validator v0.16.1
   Compiling crossbeam v0.8.3
   Compiling multiversion v0.7.3
   Compiling half v2.3.1
   Compiling is-terminal v0.4.10
   Compiling pgrx-pg-config v0.11.2
   Compiling arrayvec v0.7.4
   Compiling bincode v1.3.3
   Compiling memmap2 v0.9.3
   Compiling env_logger v0.10.1
   Compiling service v0.0.0 (/tmp/pgvecto.rs/crates/service)
   Compiling openai_api_rust v0.1.8 (https://github.com/tensorchord/openai-api.git?rev=228d54b6002e98257b3c81501a054942342f585f#228d54b6)
   Compiling pgrx-pg-sys v0.11.2
error[E0659]: `f32` is ambiguous
 --> crates/service/src/prelude/scalar/mod.rs:5:9
  |
5 | pub use f32::F32;
  |         ^^^ ambiguous name
  |
  = note: ambiguous because of multiple potential import sources
  = note: `f32` could refer to a builtin type
note: `f32` could also refer to the module defined here
 --> crates/service/src/prelude/scalar/mod.rs:2:1
  |
2 | mod f32;
  | ^^^^^^^^
  = help: use `self::f32` to refer to this module unambiguously

error[E0658]: use of unstable library feature 'int_roundings'
  --> crates/service/src/algorithms/quantization/product.rs:72:31
   |
72 |         let width = self.dims.div_ceil(self.ratio);
   |                               ^^^^^^^^
   |
   = note: see issue #88581 <https://github.com/rust-lang/rust/issues/88581> for more information
   = help: add `#![feature(int_roundings)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'int_roundings'
   --> crates/service/src/algorithms/quantization/product.rs:147:26
    |
147 |         let width = dims.div_ceil(ratio);
    |                          ^^^^^^^^
    |
    = note: see issue #88581 <https://github.com/rust-lang/rust/issues/88581> for more information
    = help: add `#![feature(int_roundings)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'int_roundings'
   --> crates/service/src/algorithms/quantization/product.rs:171:30
    |
171 |             let width = dims.div_ceil(ratio);
    |                              ^^^^^^^^
    |
    = note: see issue #88581 <https://github.com/rust-lang/rust/issues/88581> for more information
    = help: add `#![feature(int_roundings)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'int_roundings'
  --> crates/service/src/prelude/global/f16_cos.rs:92:26
   |
92 |         let width = dims.div_ceil(ratio);
   |                          ^^^^^^^^
   |
   = note: see issue #88581 <https://github.com/rust-lang/rust/issues/88581> for more information
   = help: add `#![feature(int_roundings)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'int_roundings'
   --> crates/service/src/prelude/global/f16_cos.rs:122:26
    |
122 |         let width = dims.div_ceil(ratio);
    |                          ^^^^^^^^
    |
    = note: see issue #88581 <https://github.com/rust-lang/rust/issues/88581> for more information
    = help: add `#![feature(int_roundings)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'int_roundings'
   --> crates/service/src/prelude/global/f16_cos.rs:154:26
    |
154 |         let width = dims.div_ceil(ratio);
    |                          ^^^^^^^^
    |
    = note: see issue #88581 <https://github.com/rust-lang/rust/issues/88581> for more information
    = help: add `#![feature(int_roundings)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'int_roundings'
  --> crates/service/src/prelude/global/f16_dot.rs:84:26
   |
84 |         let width = dims.div_ceil(ratio);
   |                          ^^^^^^^^
   |
   = note: see issue #88581 <https://github.com/rust-lang/rust/issues/88581> for more information
   = help: add `#![feature(int_roundings)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'int_roundings'
   --> crates/service/src/prelude/global/f16_dot.rs:110:26
    |
110 |         let width = dims.div_ceil(ratio);
    |                          ^^^^^^^^
    |
    = note: see issue #88581 <https://github.com/rust-lang/rust/issues/88581> for more information
    = help: add `#![feature(int_roundings)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'int_roundings'
   --> crates/service/src/prelude/global/f16_dot.rs:138:26
    |
138 |         let width = dims.div_ceil(ratio);
    |                          ^^^^^^^^
    |
    = note: see issue #88581 <https://github.com/rust-lang/rust/issues/88581> for more information
    = help: add `#![feature(int_roundings)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'int_roundings'
  --> crates/service/src/prelude/global/f16_l2.rs:83:26
   |
83 |         let width = dims.div_ceil(ratio);
   |                          ^^^^^^^^
   |
   = note: see issue #88581 <https://github.com/rust-lang/rust/issues/88581> for more information
   = help: add `#![feature(int_roundings)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'int_roundings'
   --> crates/service/src/prelude/global/f16_l2.rs:108:26
    |
108 |         let width = dims.div_ceil(ratio);
    |                          ^^^^^^^^
    |
    = note: see issue #88581 <https://github.com/rust-lang/rust/issues/88581> for more information
    = help: add `#![feature(int_roundings)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'int_roundings'
   --> crates/service/src/prelude/global/f16_l2.rs:135:26
    |
135 |         let width = dims.div_ceil(ratio);
    |                          ^^^^^^^^
    |
    = note: see issue #88581 <https://github.com/rust-lang/rust/issues/88581> for more information
    = help: add `#![feature(int_roundings)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'int_roundings'
  --> crates/service/src/prelude/global/f32_cos.rs:92:26
   |
92 |         let width = dims.div_ceil(ratio);
   |                          ^^^^^^^^
   |
   = note: see issue #88581 <https://github.com/rust-lang/rust/issues/88581> for more information
   = help: add `#![feature(int_roundings)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'int_roundings'
   --> crates/service/src/prelude/global/f32_cos.rs:122:26
    |
122 |         let width = dims.div_ceil(ratio);
    |                          ^^^^^^^^
    |
    = note: see issue #88581 <https://github.com/rust-lang/rust/issues/88581> for more information
    = help: add `#![feature(int_roundings)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'int_roundings'
   --> crates/service/src/prelude/global/f32_cos.rs:154:26
    |
154 |         let width = dims.div_ceil(ratio);
    |                          ^^^^^^^^
    |
    = note: see issue #88581 <https://github.com/rust-lang/rust/issues/88581> for more information
    = help: add `#![feature(int_roundings)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'int_roundings'
  --> crates/service/src/prelude/global/f32_dot.rs:84:26
   |
84 |         let width = dims.div_ceil(ratio);
   |                          ^^^^^^^^
   |
   = note: see issue #88581 <https://github.com/rust-lang/rust/issues/88581> for more information
   = help: add `#![feature(int_roundings)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'int_roundings'
   --> crates/service/src/prelude/global/f32_dot.rs:110:26
    |
110 |         let width = dims.div_ceil(ratio);
    |                          ^^^^^^^^
    |
    = note: see issue #88581 <https://github.com/rust-lang/rust/issues/88581> for more information
    = help: add `#![feature(int_roundings)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'int_roundings'
   --> crates/service/src/prelude/global/f32_dot.rs:138:26
    |
138 |         let width = dims.div_ceil(ratio);
    |                          ^^^^^^^^
    |
    = note: see issue #88581 <https://github.com/rust-lang/rust/issues/88581> for more information
    = help: add `#![feature(int_roundings)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'int_roundings'
  --> crates/service/src/prelude/global/f32_l2.rs:82:26
   |
82 |         let width = dims.div_ceil(ratio);
   |                          ^^^^^^^^
   |
   = note: see issue #88581 <https://github.com/rust-lang/rust/issues/88581> for more information
   = help: add `#![feature(int_roundings)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'int_roundings'
   --> crates/service/src/prelude/global/f32_l2.rs:107:26
    |
107 |         let width = dims.div_ceil(ratio);
    |                          ^^^^^^^^
    |
    = note: see issue #88581 <https://github.com/rust-lang/rust/issues/88581> for more information
    = help: add `#![feature(int_roundings)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'int_roundings'
   --> crates/service/src/prelude/global/f32_l2.rs:134:26
    |
134 |         let width = dims.div_ceil(ratio);
    |                          ^^^^^^^^
    |
    = note: see issue #88581 <https://github.com/rust-lang/rust/issues/88581> for more information
    = help: add `#![feature(int_roundings)]` to the crate attributes to enable

error[E0658]: use of unstable library feature 'int_roundings'
   --> crates/service/src/utils/mmap_array.rs:113:19
    |
113 |     let len = len.next_multiple_of(4096);
    |                   ^^^^^^^^^^^^^^^^
    |
    = note: see issue #88581 <https://github.com/rust-lang/rust/issues/88581> for more information
    = help: add `#![feature(int_roundings)]` to the crate attributes to enable

Some errors have detailed explanations: E0658, E0659.
For more information about an error, try `rustc --explain E0658`.
error: could not compile `service` (lib) due to 23 previous errors
warning: build failed, waiting for other jobs to finish...
error: failed to run custom build command for `pgrx-pg-sys v0.11.2`

Caused by:
  process didn't exit successfully: `/tmp/pgvecto.rs/target/release/build/pgrx-pg-sys-54f40f56ea531907/build-script-build` (exit status: 1)
  --- stdout
  cargo:rerun-if-env-changed=PGRX_BUILD_VERBOSE
  cargo:rerun-if-env-changed=PGRX_PG_SYS_GENERATE_BINDINGS_FOR_RELEASE
  cargo:rustc-cfg=nightly
  cargo:rerun-if-env-changed=PGRX_PG_CONFIG_PATH
  cargo:rerun-if-env-changed=PGRX_PG_CONFIG_AS_ENV
  cargo:rerun-if-env-changed=LLVM_CONFIG_PATH
  cargo:rerun-if-env-changed=LIBCLANG_PATH
  cargo:rerun-if-env-changed=LIBCLANG_STATIC_PATH
  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS
  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_x86_64-unknown-freebsd
  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_x86_64_unknown_freebsd
  cargo:rerun-if-env-changed=PGRX_PG_SYS_GENERATE_BINDINGS_FOR_RELEASE
  cargo:rerun-if-changed=include
  cargo:rerun-if-changed=cshim
  cargo:rerun-if-changed=/root/.pgrx/config.toml
  cargo:rerun-if-env-changed=PGRX_TARGET_INFO_PATH_PG15_x86_64-unknown-freebsd
  cargo:rerun-if-env-changed=PGRX_TARGET_INFO_PATH_PG15
  cargo:rerun-if-env-changed=PGRX_BINDGEN_NO_DETECT_INCLUDES_x86_64-unknown-freebsd
  cargo:rerun-if-env-changed=PGRX_BINDGEN_NO_DETECT_INCLUDES
  cargo:rerun-if-env-changed=PGRX_INCLUDEDIR_SERVER_PG15_x86_64-unknown-freebsd
  cargo:rerun-if-env-changed=PGRX_INCLUDEDIR_SERVER_PG15
  cargo:rerun-if-env-changed=PGRX_INCLUDEDIR_SERVER_x86_64-unknown-freebsd
  cargo:rerun-if-env-changed=PGRX_INCLUDEDIR_SERVER

  --- stderr
  build_paths=BuildPaths { manifest_dir: "/root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pgrx-pg-sys-0.11.2", out_dir: "/tmp/pgvecto.rs/target/release/build/pgrx-pg-sys-8aca4fecfc6b7056/out", src_dir: "/root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pgrx-pg-sys-0.11.2/src/include", shim_src: "/root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pgrx-pg-sys-0.11.2/cshim", shim_dst: "/tmp/pgvecto.rs/target/release/build/pgrx-pg-sys-8aca4fecfc6b7056/out/cshim" }
  Generating bindings for pg15
  pg_config --configure CLANG = None
  Bindgen found clang version 16.0.6
  found libclang at /usr/local/llvm16/lib/libclang.so.16.0.6
  Found include dirs ["/usr/local/llvm16/lib/clang/16/include"]
  /usr/local/include/postgresql/server/c.h:75:10: fatal error: 'libintl.h' file not found
  Error: bindgen failed for pg15

  Caused by:
     0: Unable to generate bindings for pg15
     1: clang diagnosed error: /usr/local/include/postgresql/server/c.h:75:10: fatal error: 'libintl.h' file not found


  Location:
      /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pgrx-pg-sys-0.11.2/build.rs:736:10
[root@test /tmp/pgvecto.rs]# cargo version && cargo pgrx --version
cargo 1.72.0-nightly
cargo-pgrx 0.11.0

@usamoi
Copy link
Collaborator

usamoi commented Jan 5, 2024

@rriski The code needs to be built with rust toolchain nightly-2023-11-15. cargo version in this toolchain is cargo 1.76.0-nightly (6790a5127 2023-11-10) so you are probably using an incorrect Rust toolchain. Did you install rustup following instructions of rustup?

@usamoi usamoi reopened this Jan 5, 2024
@rriski
Copy link
Author

rriski commented Jan 6, 2024

Ah I see now, I was getting Rust 1.72 (https://www.freshports.org/lang/rust-nightly/) because pkg uses the "Quarterly" branch by default (https://docs.freebsd.org/en/books/handbook/ports/). Resolved with:

mkdir -p /usr/local/etc/pkg/repos
echo 'FreeBSD: { url: "pkg+http://pkg.FreeBSD.org/${ABI}/latest" }' > /usr/local/etc/pkg/repos/FreeBSD.conf
pkg update -f
pkg install rust-nightly

installed rust-nightly-1.76.0.20231125. Compilation is now succesull, the only remaining issue is the missing libintl.h which is tracked in pgcentralfoundation/pgrx#470.

Build logs for completeness:

root@test:/tmp/pgvecto.rs # cargo pgrx install --sudo --release
       Using PgConfig("pg15") and `pg_config` from /usr/local/bin/pg_config
    Building extension with features pg15
     Running command "/usr/local/bin/cargo" "build" "--release" "--features" "pg15" "--no-default-features" "--message-format=json-render-diagnostics"
   Compiling pgrx-pg-sys v0.11.2
   Compiling crossbeam-channel v0.5.10
   Compiling crossbeam-queue v0.3.10
   Compiling std_detect v0.1.5 (https://github.com/tensorchord/stdarch.git?branch=avx512fp16#db0cdbc9)
   Compiling stable_deref_trait v1.2.0
   Compiling half v1.8.2
   Compiling sptr v0.3.2
   Compiling base64 v0.21.5
   Compiling winnow v0.5.31
   Compiling lazy_static v1.4.0
   Compiling webpki-roots v0.25.3
   Compiling funty v2.0.0
   Compiling either v1.9.0
error: failed to run custom build command for `pgrx-pg-sys v0.11.2`

Caused by:
  process didn't exit successfully: `/tmp/pgvecto.rs/target/release/build/pgrx-pg-sys-6a7dc33a9a6dcf00/build-script-build` (exit status: 1)
  --- stdout
  cargo:rerun-if-env-changed=PGRX_BUILD_VERBOSE
  cargo:rerun-if-env-changed=PGRX_PG_SYS_GENERATE_BINDINGS_FOR_RELEASE
  cargo:rustc-cfg=nightly
  cargo:rerun-if-env-changed=PGRX_PG_CONFIG_PATH
  cargo:rerun-if-env-changed=PGRX_PG_CONFIG_AS_ENV
  cargo:rerun-if-env-changed=LLVM_CONFIG_PATH
  cargo:rerun-if-env-changed=LIBCLANG_PATH
  cargo:rerun-if-env-changed=LIBCLANG_STATIC_PATH
  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS
  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_x86_64-unknown-freebsd
  cargo:rerun-if-env-changed=BINDGEN_EXTRA_CLANG_ARGS_x86_64_unknown_freebsd
  cargo:rerun-if-env-changed=PGRX_PG_SYS_GENERATE_BINDINGS_FOR_RELEASE
  cargo:rerun-if-changed=include
  cargo:rerun-if-changed=cshim
  cargo:rerun-if-changed=/root/.pgrx/config.toml
  cargo:rerun-if-env-changed=PGRX_TARGET_INFO_PATH_PG15_x86_64-unknown-freebsd
  cargo:rerun-if-env-changed=PGRX_TARGET_INFO_PATH_PG15
  cargo:rerun-if-env-changed=PGRX_BINDGEN_NO_DETECT_INCLUDES_x86_64-unknown-freebsd
  cargo:rerun-if-env-changed=PGRX_BINDGEN_NO_DETECT_INCLUDES
  cargo:rerun-if-env-changed=PGRX_INCLUDEDIR_SERVER_PG15_x86_64-unknown-freebsd
  cargo:rerun-if-env-changed=PGRX_INCLUDEDIR_SERVER_PG15
  cargo:rerun-if-env-changed=PGRX_INCLUDEDIR_SERVER_x86_64-unknown-freebsd
  cargo:rerun-if-env-changed=PGRX_INCLUDEDIR_SERVER

  --- stderr
  build_paths=BuildPaths { manifest_dir: "/root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pgrx-pg-sys-0.11.2", out_dir: "/tmp/pgvecto.rs/target/release/build/pgrx-pg-sys-039aa4019a2b678b/out", src_dir: "/root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pgrx-pg-sys-0.11.2/src/include", shim_src: "/root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pgrx-pg-sys-0.11.2/cshim", shim_dst: "/tmp/pgvecto.rs/target/release/build/pgrx-pg-sys-039aa4019a2b678b/out/cshim" }
  Generating bindings for pg15
  pg_config --configure CLANG = None
  Bindgen found clang version 16.0.6
  found libclang at /usr/local/llvm16/lib/libclang.so.16.0.6
  Found include dirs ["/usr/local/llvm16/lib/clang/16/include"]
  /usr/local/include/postgresql/server/c.h:75:10: fatal error: 'libintl.h' file not found
  Error: bindgen failed for pg15

  Caused by:
     0: Unable to generate bindings for pg15
     1: clang diagnosed error: /usr/local/include/postgresql/server/c.h:75:10: fatal error: 'libintl.h' file not found


  Location:
      /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pgrx-pg-sys-0.11.2/build.rs:736:10
warning: build failed, waiting for other jobs to finish...

Thank you for the help, this issue can be closed!

@rriski rriski closed this as completed Jan 6, 2024
@gaocegege
Copy link
Member

Maybe we could support pkg-install in the future.

Ref https://www.freshports.org/databases/pg_vector/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants