From 2f6975a577614cb0d5eb9a839a2f03bd0f480286 Mon Sep 17 00:00:00 2001 From: Keming Date: Fri, 1 Nov 2024 16:38:44 +0800 Subject: [PATCH 1/8] chore: add CI lint and build test Signed-off-by: Keming --- .github/workflows/rust.yml | 80 +++++++++++++++++++++++++++++++++++++ .github/workflows/style.yml | 39 ++++++++++++++++++ .taplo.toml | 18 +++++++++ Cargo.toml | 4 +- 4 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/rust.yml create mode 100644 .github/workflows/style.yml create mode 100644 .taplo.toml diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml new file mode 100644 index 0000000..afc961f --- /dev/null +++ b/.github/workflows/rust.yml @@ -0,0 +1,80 @@ +name: Rust + +on: + pull_request: + paths: + - '.github/workflows/rust.yml' + - 'src/**' + - 'Cargo.lock' + - 'Cargo.toml' + - '*.control' + - 'rust-toolchain.toml' + push: + branches: + - main + paths: + - '.github/workflows/rust.yml' + - 'src/**' + - 'Cargo.lock' + - 'Cargo.toml' + - '*.control' + - 'rust-toolchain.toml' + merge_group: + workflow_dispatch: + +concurrency: + group: ${{ github.ref }}-${{ github.workflow }} + cancel-in-progress: true + +env: + CARGO_TERM_COLOR: always + RUST_BACKTRACE: 1 + SCCACHE_GHA_ENABLED: "true" + RUSTC_WRAPPER: "sccache" + RUSTFLAGS: "-Dwarnings" + CARGO_PROFILE_OPT_BUILD_OVERRIDE_DEBUG: true + +jobs: + test: + runs-on: ubuntu-latest + timeout-minutes: 30 + strategy: + matrix: + arch: ["x86_64", "aarch64"] + + steps: + - uses: actions/checkout@v4 + - name: Set up Rust + uses: dtolnay/rust-toolchain@stable + - name: Set up dev environment + run: | + sudo apt-get remove -y '^postgres.*' '^libpq.*' '^clang.*' '^llvm.*' '^libclang.*' '^libllvm.*' '^mono-llvm.*' + sudo apt-get purge -y '^postgres.*' '^libpq.*' '^clang.*' '^llvm.*' '^libclang.*' '^libllvm.*' '^mono-llvm.*' + sudo apt-get update + sudo apt-get install -y build-essential crossbuild-essential-arm64 + sudo apt-get install -y qemu-user-static + touch ~/.cargo/config.toml + echo 'target.aarch64-unknown-linux-gnu.linker = "aarch64-linux-gnu-gcc"' >> ~/.cargo/config.toml + echo 'target.aarch64-unknown-linux-gnu.runner = ["qemu-aarch64-static", "-L", "/usr/aarch64-linux-gnu"]' >> ~/.cargo/config.toml + rustup target add x86_64-unknown-linux-gnu + rustup target add aarch64-unknown-linux-gnu + - name: Cache + uses: mozilla-actions/sccache-action@v0.0.6 + - name: Set up pgrx + run: | + cargo install cargo-pgrx --locked + cargo pgrx init + - name: Clippy + run: | + for v in {12..17}; do + cargo clippy --target ${{ matrix.arch }}-unknown-linux-gnu --features "pg$v" -- -D warnings + done + - name: Build + run: | + for v in {12..17}; do + cargo build --lib --target ${{ matrix.arch }}-unknown-linux-gnu --features "pg$v" + done + - name: Test + run: | + # pg agnostic tests + cargo test --no-fail-fast --target $ARCH-unknown-linux-gnu --features pg17 diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml new file mode 100644 index 0000000..f8bc6db --- /dev/null +++ b/.github/workflows/style.yml @@ -0,0 +1,39 @@ +name: Style + +on: + pull_request: + branches: + - main + push: + branches: + - main + merge_group: + workflow_dispatch: + +concurrency: + group: ${{ github.ref }}-${{ github.workflow }} + cancel-in-progress: true + +env: + CARGO_TERM_COLOR: always + +jobs: + lint: + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@v4 + + - name: Typos + uses: crate-ci/typos@master + + - name: TOML lint + run: | + curl -fsSL https://github.com/tamasfe/taplo/releases/latest/download/taplo-full-linux-x86_64.gz | gzip -d - | install -m 755 /dev/stdin /usr/local/bin/taplo + taplo fmt --check + + - name: Set up Rust + uses: dtolnay/rust-toolchain@stable + - name: Cargo Lint + run: | + cargo fmt -- --check diff --git a/.taplo.toml b/.taplo.toml new file mode 100644 index 0000000..fbe01c2 --- /dev/null +++ b/.taplo.toml @@ -0,0 +1,18 @@ +[formatting] +indent_string = " " + +[[rule]] +keys = ["dependencies", "*-denpendencies", "lints", "patch.*"] + +[rule.formatting] +reorder_keys = false +reorder_arrays = true +align_comments = true + +[[rule]] +keys = ["profile.*"] + +[rule.formatting] +reorder_keys = true +reorder_arrays = true +align_comments = true diff --git a/Cargo.toml b/Cargo.toml index 8b8c003..35cfccb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,12 +48,12 @@ rust.unused_lifetimes = "warn" rust.unused_qualifications = "warn" [profile.opt] +debug-assertions = false inherits = "dev" opt-level = 3 -debug-assertions = false overflow-checks = false [profile.release] -lto = "fat" codegen-units = 1 debug = true +lto = "fat" From 6c6c2fecb4273a98028796dd9a8a4cdc4d5461d6 Mon Sep 17 00:00:00 2001 From: Keming Date: Fri, 1 Nov 2024 16:45:51 +0800 Subject: [PATCH 2/8] fix typo Signed-off-by: Keming --- bench/index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bench/index.py b/bench/index.py index 4fde97f..97b67a0 100644 --- a/bench/index.py +++ b/bench/index.py @@ -179,7 +179,7 @@ async def main(dataset): await add_embeddings(conn, args.name, args.dim, dataset["train"]) index_finish = asyncio.Event() - # Need a seperate connection for monitor process + # Need a separate connection for monitor process monitor_conn = await create_connection(url) monitor_task = monitor_index_build( monitor_conn, From 5f58f239641ec53c395652da36453b1e42f23e32 Mon Sep 17 00:00:00 2001 From: Keming Date: Fri, 1 Nov 2024 17:19:32 +0800 Subject: [PATCH 3/8] fix pgrx build dependencies Signed-off-by: Keming --- .github/workflows/rust.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index afc961f..fd2abe4 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -37,7 +37,6 @@ env: jobs: test: runs-on: ubuntu-latest - timeout-minutes: 30 strategy: matrix: arch: ["x86_64", "aarch64"] @@ -51,7 +50,8 @@ jobs: sudo apt-get remove -y '^postgres.*' '^libpq.*' '^clang.*' '^llvm.*' '^libclang.*' '^libllvm.*' '^mono-llvm.*' sudo apt-get purge -y '^postgres.*' '^libpq.*' '^clang.*' '^llvm.*' '^libclang.*' '^libllvm.*' '^mono-llvm.*' sudo apt-get update - sudo apt-get install -y build-essential crossbuild-essential-arm64 + sudo apt-get install -y build-essential crossbuild-essential-arm64 clang + sudo apt-get install -y libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt-dev libssl-dev libxml2-utils xsltproc ccache pkg-config sudo apt-get install -y qemu-user-static touch ~/.cargo/config.toml echo 'target.aarch64-unknown-linux-gnu.linker = "aarch64-linux-gnu-gcc"' >> ~/.cargo/config.toml From 919ebce0960f5001e5e4d2dcaebdbb2eca5b388e Mon Sep 17 00:00:00 2001 From: Keming Date: Fri, 1 Nov 2024 23:46:56 +0800 Subject: [PATCH 4/8] use pgrx docker image to accelerate the dev-build/clippy/test Signed-off-by: Keming --- .github/workflows/rust.yml | 35 ++++++++++++----------------------- docker/pgrx.Dockerfile | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 23 deletions(-) create mode 100644 docker/pgrx.Dockerfile diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index fd2abe4..67c11cc 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -40,41 +40,30 @@ jobs: strategy: matrix: arch: ["x86_64", "aarch64"] + env: + PGRX_IMAGE: "kemingy/pgrx:0.12.6" steps: - uses: actions/checkout@v4 - - name: Set up Rust - uses: dtolnay/rust-toolchain@stable - - name: Set up dev environment - run: | - sudo apt-get remove -y '^postgres.*' '^libpq.*' '^clang.*' '^llvm.*' '^libclang.*' '^libllvm.*' '^mono-llvm.*' - sudo apt-get purge -y '^postgres.*' '^libpq.*' '^clang.*' '^llvm.*' '^libclang.*' '^libllvm.*' '^mono-llvm.*' - sudo apt-get update - sudo apt-get install -y build-essential crossbuild-essential-arm64 clang - sudo apt-get install -y libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt-dev libssl-dev libxml2-utils xsltproc ccache pkg-config - sudo apt-get install -y qemu-user-static - touch ~/.cargo/config.toml - echo 'target.aarch64-unknown-linux-gnu.linker = "aarch64-linux-gnu-gcc"' >> ~/.cargo/config.toml - echo 'target.aarch64-unknown-linux-gnu.runner = ["qemu-aarch64-static", "-L", "/usr/aarch64-linux-gnu"]' >> ~/.cargo/config.toml - rustup target add x86_64-unknown-linux-gnu - rustup target add aarch64-unknown-linux-gnu - name: Cache uses: mozilla-actions/sccache-action@v0.0.6 - - name: Set up pgrx + - name: Set up docker images and permissions run: | - cargo install cargo-pgrx --locked - cargo pgrx init + docker pull $PGRX_IMAGE + echo "Default user: $(id -u):$(id -g)" + sudo chown -R 1000:1000 . + - name: Clippy run: | - for v in {12..17}; do - cargo clippy --target ${{ matrix.arch }}-unknown-linux-gnu --features "pg$v" -- -D warnings + for v in {14..17}; do + docker run --rm -v .:/workspace $PGRX_IMAGE clippy --target ${{ matrix.arch }}-unknown-linux-gnu --features "pg$v" -- -D warnings done - name: Build run: | - for v in {12..17}; do - cargo build --lib --target ${{ matrix.arch }}-unknown-linux-gnu --features "pg$v" + for v in {14..17}; do + docker run --rm -v .:/workspace $PGRX_IMAGE build --lib --target ${{ matrix.arch }}-unknown-linux-gnu --features "pg$v" done - name: Test run: | # pg agnostic tests - cargo test --no-fail-fast --target $ARCH-unknown-linux-gnu --features pg17 + docker run --rm -v .:/workspace $PGRX_IMAGE test --no-fail-fast --target $ARCH-unknown-linux-gnu --features pg17 diff --git a/docker/pgrx.Dockerfile b/docker/pgrx.Dockerfile new file mode 100644 index 0000000..01bbc92 --- /dev/null +++ b/docker/pgrx.Dockerfile @@ -0,0 +1,34 @@ +FROM ubuntu:22.04 + +ARG PGRX_VERSION=0.12.6 +ARG RUSTC_WRAPPER=sccache + +ENV DEBIAN_FRONTEND=noninteractive \ + LANG=en_US.UTF-8 \ + LC_ALL=en_US.UTF-8 \ + RUSTC_WRAPPER=${RUSTC_WRAPPER} \ + RUSTFLAGS="-Dwarnings" + +RUN apt update && \ + apt install -y --no-install-recommends \ + curl \ + ca-certificates \ + build-essential \ + crossbuild-essential-arm64 \ + qemu-user-static \ + libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt-dev libssl-dev libxml2-utils xsltproc ccache pkg-config \ + clang && \ + rm -rf /var/lib/apt/lists/* + +USER ubuntu +ENV PATH="$PATH:/home/ubuntu/.cargo/bin" +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain=none -y + +WORKDIR /workspace +COPY rust-toolchain.toml /workspace/rust-toolchain.toml +RUN rustup target add x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu + +RUN cargo install cargo-pgrx --locked --version=${PGRX_VERSION} && \ + cargo pgrx init + +ENTRYPOINT [ "cargo" ] From a4656b16ed882d8568b34c217499604ad00c3445 Mon Sep 17 00:00:00 2001 From: Keming Date: Mon, 4 Nov 2024 15:11:02 +0800 Subject: [PATCH 5/8] fix pgrx docker image ubuntu 22.04 aarch64 Signed-off-by: Keming --- .github/workflows/rust.yml | 2 +- .taplo.toml | 2 +- Cargo.toml | 15 ++++++++------- docker/pgrx.Dockerfile | 8 ++++++-- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 67c11cc..454943a 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -66,4 +66,4 @@ jobs: - name: Test run: | # pg agnostic tests - docker run --rm -v .:/workspace $PGRX_IMAGE test --no-fail-fast --target $ARCH-unknown-linux-gnu --features pg17 + docker run --rm -v .:/workspace $PGRX_IMAGE test --no-fail-fast --target ${{ matrix.arch }}-unknown-linux-gnu --features pg17 diff --git a/.taplo.toml b/.taplo.toml index fbe01c2..2866c77 100644 --- a/.taplo.toml +++ b/.taplo.toml @@ -5,7 +5,7 @@ indent_string = " " keys = ["dependencies", "*-denpendencies", "lints", "patch.*"] [rule.formatting] -reorder_keys = false +reorder_keys = true reorder_arrays = true align_comments = true diff --git a/Cargo.toml b/Cargo.toml index 0cdd317..bd6643f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,20 +21,21 @@ pg16 = ["pgrx/pg16", "pgrx-catalog/pg16"] pg17 = ["pgrx/pg17", "pgrx-catalog/pg17"] [dependencies] +paste = "1" pgrx = { version = "=0.12.8", default-features = false, features = ["cshim"] } pgrx-catalog = "0.1.0" +rand = "0.8.5" +rand_chacha = "0.3.1" +rand_distr = "0.4.3" +serde = "1" +toml = "0.8.19" +validator = "0.18.1" + base = { git = "https://github.com/tensorchord/pgvecto.rs.git", branch = "rabbithole-2" } common = { git = "https://github.com/tensorchord/pgvecto.rs.git", branch = "rabbithole-2" } detect = { git = "https://github.com/tensorchord/pgvecto.rs.git", branch = "rabbithole-2" } k_means = { git = "https://github.com/tensorchord/pgvecto.rs.git", branch = "rabbithole-2" } quantization = { git = "https://github.com/tensorchord/pgvecto.rs.git", branch = "rabbithole-2" } -paste = "1" -serde = "1" -toml = "0.8.19" -rand = "0.8.5" -rand_chacha = "0.3.1" -rand_distr = "0.4.3" -validator = "0.18.1" # lock algebra version forever so that the QR decomposition never changes for same input nalgebra = { version = "=0.33.0", default-features = false } diff --git a/docker/pgrx.Dockerfile b/docker/pgrx.Dockerfile index 01bbc92..3d29acb 100644 --- a/docker/pgrx.Dockerfile +++ b/docker/pgrx.Dockerfile @@ -1,12 +1,11 @@ +# CNPG only support Debian 12 (Bookworm) FROM ubuntu:22.04 ARG PGRX_VERSION=0.12.6 -ARG RUSTC_WRAPPER=sccache ENV DEBIAN_FRONTEND=noninteractive \ LANG=en_US.UTF-8 \ LC_ALL=en_US.UTF-8 \ - RUSTC_WRAPPER=${RUSTC_WRAPPER} \ RUSTFLAGS="-Dwarnings" RUN apt update && \ @@ -20,12 +19,17 @@ RUN apt update && \ clang && \ rm -rf /var/lib/apt/lists/* +# create a non-root user (make it compatible with Ubuntu 24.04) +RUN useradd -u 1000 -U -m ubuntu USER ubuntu ENV PATH="$PATH:/home/ubuntu/.cargo/bin" RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain=none -y WORKDIR /workspace COPY rust-toolchain.toml /workspace/rust-toolchain.toml +RUN set -ex; \ + echo 'target.aarch64-unknown-linux-gnu.linker = "aarch64-linux-gnu-gcc"' >> ~/.cargo/config.toml; \ + echo 'target.aarch64-unknown-linux-gnu.runner = ["qemu-aarch64-static", "-L", "/usr/aarch64-linux-gnu"]' >> ~/.cargo/config.toml RUN rustup target add x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu RUN cargo install cargo-pgrx --locked --version=${PGRX_VERSION} && \ From f6b9d2abbfc30ee6df2878bf9fb41cc2eef82313 Mon Sep 17 00:00:00 2001 From: Keming Date: Mon, 4 Nov 2024 17:08:16 +0800 Subject: [PATCH 6/8] address commments Signed-off-by: Keming --- .github/workflows/rust.yml | 4 +--- .github/workflows/style.yml | 2 +- .taplo.toml | 10 +--------- docker/pgrx.Dockerfile | 2 +- 4 files changed, 4 insertions(+), 14 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 454943a..1aa6ef4 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -41,12 +41,10 @@ jobs: matrix: arch: ["x86_64", "aarch64"] env: - PGRX_IMAGE: "kemingy/pgrx:0.12.6" + PGRX_IMAGE: "kemingy/pgrx:0.12.8" steps: - uses: actions/checkout@v4 - - name: Cache - uses: mozilla-actions/sccache-action@v0.0.6 - name: Set up docker images and permissions run: | docker pull $PGRX_IMAGE diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index f8bc6db..c3b8f89 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -36,4 +36,4 @@ jobs: uses: dtolnay/rust-toolchain@stable - name: Cargo Lint run: | - cargo fmt -- --check + cargo fmt --check diff --git a/.taplo.toml b/.taplo.toml index 2866c77..d9a9fda 100644 --- a/.taplo.toml +++ b/.taplo.toml @@ -2,15 +2,7 @@ indent_string = " " [[rule]] -keys = ["dependencies", "*-denpendencies", "lints", "patch.*"] - -[rule.formatting] -reorder_keys = true -reorder_arrays = true -align_comments = true - -[[rule]] -keys = ["profile.*"] +keys = ["dependencies", "*-denpendencies", "lints", "patch.*", "profile.*"] [rule.formatting] reorder_keys = true diff --git a/docker/pgrx.Dockerfile b/docker/pgrx.Dockerfile index 3d29acb..b9ada9a 100644 --- a/docker/pgrx.Dockerfile +++ b/docker/pgrx.Dockerfile @@ -1,7 +1,7 @@ # CNPG only support Debian 12 (Bookworm) FROM ubuntu:22.04 -ARG PGRX_VERSION=0.12.6 +ARG PGRX_VERSION=0.12.8 ENV DEBIAN_FRONTEND=noninteractive \ LANG=en_US.UTF-8 \ From 35b6f23ac038e25879890d3e20884bb4e12c128a Mon Sep 17 00:00:00 2001 From: Keming Date: Mon, 4 Nov 2024 17:31:07 +0800 Subject: [PATCH 7/8] Update .github/workflows/style.yml Co-authored-by: usamoi --- .github/workflows/style.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index c3b8f89..230d7d0 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -32,8 +32,6 @@ jobs: curl -fsSL https://github.com/tamasfe/taplo/releases/latest/download/taplo-full-linux-x86_64.gz | gzip -d - | install -m 755 /dev/stdin /usr/local/bin/taplo taplo fmt --check - - name: Set up Rust - uses: dtolnay/rust-toolchain@stable - name: Cargo Lint run: | cargo fmt --check From 0f5c71e0248ff064a2c0f0bdc891ca7a4939578e Mon Sep 17 00:00:00 2001 From: Keming Date: Tue, 5 Nov 2024 11:10:37 +0800 Subject: [PATCH 8/8] enable sccache Signed-off-by: Keming --- .github/workflows/rust.yml | 24 +++++++++++++----------- docker/pgrx.Dockerfile | 36 ++++++++++++++++++++++++++++++------ 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 1aa6ef4..018139a 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -26,14 +26,6 @@ concurrency: group: ${{ github.ref }}-${{ github.workflow }} cancel-in-progress: true -env: - CARGO_TERM_COLOR: always - RUST_BACKTRACE: 1 - SCCACHE_GHA_ENABLED: "true" - RUSTC_WRAPPER: "sccache" - RUSTFLAGS: "-Dwarnings" - CARGO_PROFILE_OPT_BUILD_OVERRIDE_DEBUG: true - jobs: test: runs-on: ubuntu-latest @@ -45,6 +37,16 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Configure sccache + uses: actions/github-script@v7 + with: + script: | + const url = process.env.ACTIONS_CACHE_URL || ''; + const token = process.env.ACTIONS_RUNTIME_TOKEN || ''; + core.exportVariable( + 'CACHE_ENVS', + `-e CARGO_INCREMENTAL=0 -e SCCACHE_GHA_ENABLED=true -e RUSTC_WRAPPER=sccache -e ACTIONS_CACHE_URL=${url} -e ACTIONS_RUNTIME_TOKEN=${token}`, + ); - name: Set up docker images and permissions run: | docker pull $PGRX_IMAGE @@ -54,14 +56,14 @@ jobs: - name: Clippy run: | for v in {14..17}; do - docker run --rm -v .:/workspace $PGRX_IMAGE clippy --target ${{ matrix.arch }}-unknown-linux-gnu --features "pg$v" -- -D warnings + docker run --rm -v .:/workspace $CACHE_ENVS $PGRX_IMAGE clippy --target ${{ matrix.arch }}-unknown-linux-gnu --features "pg$v" -- -D warnings done - name: Build run: | for v in {14..17}; do - docker run --rm -v .:/workspace $PGRX_IMAGE build --lib --target ${{ matrix.arch }}-unknown-linux-gnu --features "pg$v" + docker run --rm -v .:/workspace $CACHE_ENVS $PGRX_IMAGE build --lib --target ${{ matrix.arch }}-unknown-linux-gnu --features "pg$v" done - name: Test run: | # pg agnostic tests - docker run --rm -v .:/workspace $PGRX_IMAGE test --no-fail-fast --target ${{ matrix.arch }}-unknown-linux-gnu --features pg17 + docker run --rm -v .:/workspace $CACHE_ENVS $PGRX_IMAGE test --no-fail-fast --target ${{ matrix.arch }}-unknown-linux-gnu --features pg17 diff --git a/docker/pgrx.Dockerfile b/docker/pgrx.Dockerfile index b9ada9a..920817b 100644 --- a/docker/pgrx.Dockerfile +++ b/docker/pgrx.Dockerfile @@ -2,22 +2,41 @@ FROM ubuntu:22.04 ARG PGRX_VERSION=0.12.8 +ARG SCCACHE_VERSION=0.8.2 ENV DEBIAN_FRONTEND=noninteractive \ LANG=en_US.UTF-8 \ LC_ALL=en_US.UTF-8 \ - RUSTFLAGS="-Dwarnings" + RUSTFLAGS="-Dwarnings" \ + RUST_BACKTRACE=1 \ + CARGO_TERM_COLOR=always -RUN apt update && \ +RUN set -eux; \ + apt update; \ apt install -y --no-install-recommends \ curl \ ca-certificates \ build-essential \ + postgresql-common gnupg \ crossbuild-essential-arm64 \ qemu-user-static \ libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt-dev libssl-dev libxml2-utils xsltproc ccache pkg-config \ - clang && \ - rm -rf /var/lib/apt/lists/* + clang + +# set up sccache +RUN set -ex; \ + curl -fsSL -o sccache.tar.gz https://github.com/mozilla/sccache/releases/download/v${SCCACHE_VERSION}/sccache-v${SCCACHE_VERSION}-x86_64-unknown-linux-musl.tar.gz; \ + tar -xzf sccache.tar.gz --strip-components=1; \ + rm sccache.tar.gz; \ + mv sccache /usr/local/bin/ + +RUN /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y +# install all the PostgresQL +RUN set -ex; \ + for v in $(seq 14 17); do \ + apt install -y --no-install-recommends postgresql-$v postgresql-server-dev-$v; \ + done; \ + rm -rf /var/lib/apt/lists/*; # create a non-root user (make it compatible with Ubuntu 24.04) RUN useradd -u 1000 -U -m ubuntu @@ -27,12 +46,17 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --defau WORKDIR /workspace COPY rust-toolchain.toml /workspace/rust-toolchain.toml +# ref: https://github.com/pgcentralfoundation/pgrx/blob/develop/docs/src/extension/build/cross-compile.md RUN set -ex; \ echo 'target.aarch64-unknown-linux-gnu.linker = "aarch64-linux-gnu-gcc"' >> ~/.cargo/config.toml; \ echo 'target.aarch64-unknown-linux-gnu.runner = ["qemu-aarch64-static", "-L", "/usr/aarch64-linux-gnu"]' >> ~/.cargo/config.toml RUN rustup target add x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu -RUN cargo install cargo-pgrx --locked --version=${PGRX_VERSION} && \ - cargo pgrx init +RUN cargo install cargo-pgrx --locked --version=${PGRX_VERSION} + +RUN set -ex; \ + for v in $(seq 14 17); do \ + cargo pgrx init --pg$v=/usr/lib/postgresql/$v/bin/pg_config; \ + done; ENTRYPOINT [ "cargo" ]