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

Schema generation empty on alpine #340

Closed
JamesGuthrie opened this issue Dec 21, 2021 · 5 comments
Closed

Schema generation empty on alpine #340

JamesGuthrie opened this issue Dec 21, 2021 · 5 comments

Comments

@JamesGuthrie
Copy link
Contributor

I'm hitting an issue where the generated schema file is empty on alpine linux.

The most minimal case that I have for reproduction at the moment is the following Dockerfile

FROM timescale/timescaledb:2.5.0-pg14

RUN apk add --no-cache --virtual .build-deps \
        coreutils \
        dpkg-dev dpkg \
        gcc \
        libc-dev \
        make \
        util-linux-dev \
        clang \
        llvm \
        git \
        llvm-dev clang-libs \
        dpkg-dev dpkg \
        gcc \
        libc-dev \
        libedit-dev \
        libxml2-dev \
        libxslt-dev \
        linux-headers \
        clang g++ \
        make \
        openssl-dev \
        util-linux-dev \
        zlib-dev \
        icu-dev \
        rustup

USER postgres

ENV PATH=/usr/local/cargo/bin:$PATH \
    RUST_VERSION=1.57.0 \
    # prevents some issues with openssl
    RUSTFLAGS="-C target-feature=-crt-static"

RUN set -eux; \
    apkArch="$(apk --print-arch)"; \
    case "$apkArch" in \
        x86_64) rustArch='x86_64-unknown-linux-musl'; ;; \
        aarch64) rustArch='aarch64-unknown-linux-musl'; ;; \
        *) echo >&2 "unsupported architecture: $apkArch"; exit 1 ;; \
    esac; \
    rustup-init -y --no-modify-path --profile minimal  --component rustfmt --default-toolchain $RUST_VERSION --default-host ${rustArch};

RUN source $HOME/.cargo/env && cargo install cargo-pgx; \
    cargo pgx init --pg14 /usr/local/bin/pg_config

RUN source $HOME/.cargo/env && cd && \
    cargo pgx new test && \
    cd test && \
    cargo pgx schema -f pg14

Creating that Dockerfile and then running:

docker build --platform=linux/arm64/v8 . -t pgx-empty-schema-repro

docker run -ti pgx-empty-schema-repro bash -c 'cat $HOME/test/sql/test-1.0.sql'
@Hoverbear
Copy link
Contributor

This is quite curious!

It seems that while the generated libtest.so has the required symbols:

0ab4bd9d41d7:~/test$ objdump -TC target/debug/libtest.so | grep __pgx_
0000000000016f00 g    DF .text  000000000000012b  Base        __pgx_marker
0000000000017050 g    DF .text  000000000000045e  Base        __pgx_internals_fn_hello_test
0ab4bd9d41d7:~/test$ nm -D target/debug/libtest.so  | grep __pgx_
0000000000017050 T __pgx_internals_fn_hello_test
0000000000016f00 T __pgx_marker

The sql-generator does not:

0ab4bd9d41d7:~/test$ objdump -TC target/debug/sql-generator | grep __pgx_
0ab4bd9d41d7:~/test$ nm -D target/debug/sql-generator | grep __pgx_

Where it's curious is that the schema command can see the marker:

0ab4bd9d41d7:~/test$ cargo pgx schema pg14 -f
    Building SQL generator with features `pg14`
"cargo" "build" "--bin" "sql-generator" "--features" "pg14" "--no-default-features"
    Finished dev [unoptimized + debuginfo] target(s) in 0.09s
 Discovering SQL entities
Got object: Ok(Elf(ElfObject { code_id: None, debug_id: DebugId { uuid: "8cd3cea9-57bb-b530-c9f1-e5c0b48a5549", appendix: 0 }, arch: Amd64, kind: Library, load_address: 0x0, has_symbols: true, has_debug_info: true, has_unwind_info: true, is_malformed: false }))
  Got marker: Symbol { name: "_ZN4test12__pgx_marker28_$u7b$$u7b$closure$u7d$$u7d$17hbeb91504364f6a32E", address: 0x777e40, size: 0xf }
  Got marker: Symbol { name: "__pgx_marker", address: 0x7787b0, size: 0x12b }
  Discovered 0 SQL entities: 0 schemas (0 unique), 0 functions, 0 types, 0 enums, 0 sqls, 0 ords, 0 hashes
running SQL generator with features `pg14`
"cargo" "run" "--bin" "sql-generator" "--features" "pg14" "--no-default-features" "--" "--sql" "sql/test-1.0.sql"
    Finished dev [unoptimized + debuginfo] target(s) in 0.08s
     Running `target/debug/sql-generator --sql sql/test-1.0.sql`

I wonder if Alpine will require special linker script hacking...

@JamesGuthrie
Copy link
Contributor Author

So I managed to get to the bottom of this. The issue is that the aarch64-unknown-linux-musl target is missing in the cargo_config template file. I was wondering if it would be possible to set the custom linker for all targets, but I'm not sure fi that's a wise idea. Otherwise it would be nice to somehow detect that the target is not supported yet and error out or something.

@Hoverbear
Copy link
Contributor

I did look into the possibility of adding all targets, however it wasn't possible. I would have preferred that for sure.

Hoverbear pushed a commit that referenced this issue Jan 5, 2022
Alpine uses musl libc, which is identified as a different compilation
target by the Rust compiler. This target was not configured to use pgx's
magical linker script, so the symbols which the schema generator expects
to be present were not present.

Fixes #340
@JamesGuthrie
Copy link
Contributor Author

My change fixed this, so I'm closing it.

@Hoverbear
Copy link
Contributor

Thanks!!!

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

No branches or pull requests

2 participants