tcdi / plrust

A Rust procedural language handler for PostgreSQL
PostgreSQL License
1.1k stars 32 forks source link

Plrustc will not compile on alpine/postgres. #372

Open therealjasonkenney opened 1 year ago

therealjasonkenney commented 1 year ago

I get this output when running the build script for plrustc:

3.516 + env 'RUSTFLAGS=-Clink-args=-Wl,-rpath,/usr/local/rustup/toolchains/1.70.0-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib -Zunstable-options -Zbinary-dep-depinfo' cargo build --release -p plrustc --bin plrustc --target x86_64-unknown-linux-musl
3.800     Updating crates.io index
4.751  Downloading crates ...
5.213   Downloaded once_cell v1.18.0
5.725   Downloaded libc v0.2.147
5.872    Compiling libc v0.2.147
5.872    Compiling once_cell v1.18.0
7.969    Compiling plrustc v1.2.3 (/tmp/plrust-1.2.3/plrustc/plrustc)
8.681 error: crate `rustc_ast` required to be available in rlib format, but was not found in this form
8.681

I looked in the library path, and indeed many rlibs are missing.

 FROM rust:alpine3.17 AS rust-builder

 RUN rustup update 1.70.0 \
    && rustup default 1.70.0 \
    && rustup component add --toolchain 1.70.0 llvm-tools-preview rustc-dev rust-src

  RUN wget -qO /tmp/plrust.tar.gz https://github.com/tcdi/plrust/archive/refs/tags/v1.2.3.tar.gz  \
    && tar -xvzf /tmp/plrust.tar.gz -C /tmp

  WORKDIR /tmp/plrust-1.2.3/plrustc

   RUN /bin/ash -x ./build.sh

pgrx, plrust both compile without errors. Just plrustc breaks.

eeeebbbbrrrr commented 1 year ago

I don't know if this will help, but for alpine you almost always need:

ENV RUSTFLAGS="-C target-feature=-crt-static"

before you start compiling anything. Give that a shot. Offhand I don't know if plrustc/build.sh might need to be updated or if you can handle it directly in your Dockerfile.

therealjasonkenney commented 1 year ago

Thanks, I managed to get it all compiled, mostly by not using plrustc/build.sh and manually adding a json file to postgrestd. However a new problem arrises, how do I get those rust flags to be used when Postgres compiles a rust function?

workingjubilee commented 1 year ago

Proper support would involve threading full support for a musl libc distro in all locations.