From 5bd1792ee00c14523f92eb577b9d72e397a4f459 Mon Sep 17 00:00:00 2001 From: Usamoi Date: Mon, 18 Dec 2023 17:38:31 +0800 Subject: [PATCH] fix: do not config cross compilation in config.toml, document it in docs (#198) * fix: do not config cross compilation in config.toml, document it in docs Signed-off-by: usamoi * docs: improve install-from-source-code instructions Signed-off-by: usamoi * ci: enable all checks for all PRs Signed-off-by: usamoi --------- Signed-off-by: usamoi --- .cargo/config.toml | 10 ---------- .github/workflows/check.yml | 32 ++++++-------------------------- .github/workflows/release.yml | 2 ++ docs/installation.md | 31 +++++++++++++++++++++++++++---- scripts/ci_setup.sh | 2 ++ 5 files changed, 37 insertions(+), 40 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 52579941e..c4db64902 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -4,13 +4,3 @@ rustdocflags = ["--document-private-items"] [target.'cfg(target_os="macos")'] # Postgres symbols won't be available until runtime rustflags = ["-Clink-arg=-Wl,-undefined,dynamic_lookup"] - -[target.x86_64-unknown-linux-gnu] -linker = "x86_64-linux-gnu-gcc" - -[target.aarch64-unknown-linux-gnu] -linker = "aarch64-linux-gnu-gcc" - -[env] -BINDGEN_EXTRA_CLANG_ARGS_x86_64_unknown_linux_gnu = "-isystem /usr/x86_64-linux-gnu/include/ -ccc-gcc-name x86_64-linux-gnu-gcc" -BINDGEN_EXTRA_CLANG_ARGS_aarch64_unknown_linux_gnu = "-isystem /usr/aarch64-linux-gnu/include/ -ccc-gcc-name aarch64-linux-gnu-gcc" diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 76ccaa2bb..4be1b99b6 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -42,35 +42,15 @@ env: RUSTFLAGS: "-Dwarnings" jobs: - matrix: - runs-on: ubuntu-latest - outputs: - matrix: ${{ steps.main.outputs.matrix }} - steps: - - uses: actions/github-script@v7 - id: main - with: - script: | - let matrix; - if ("${{ github.event_name }}" == "pull_request") { - matrix = [ - { version: 15, os: "ubuntu-latest" }, - ]; - } else { - matrix = [ - { version: 12, os: "ubuntu-latest" }, - { version: 13, os: "ubuntu-latest" }, - { version: 14, os: "ubuntu-latest" }, - { version: 15, os: "ubuntu-latest" }, - { version: 16, os: "ubuntu-latest" }, - ]; - } - core.setOutput('matrix', JSON.stringify(matrix)); check: - needs: matrix strategy: matrix: - include: ${{ fromJson(needs.matrix.outputs.matrix) }} + include: + - { version: 12, os: "ubuntu-latest" } + - { version: 13, os: "ubuntu-latest" } + - { version: 14, os: "ubuntu-latest" } + - { version: 15, os: "ubuntu-latest" } + - { version: 16, os: "ubuntu-latest" } runs-on: ${{ matrix.os }} env: VERSION: ${{ matrix.version }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 551ac1bd7..95858903c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -91,6 +91,8 @@ jobs: cargo pgrx init --pg${{ matrix.version }}=/usr/lib/postgresql/${{ matrix.version }}/bin/pg_config if [[ "${{ matrix.arch }}" == "aarch64" ]]; then sudo apt-get -y install crossbuild-essential-arm64 + echo 'target.aarch64-unknown-linux-gnu.linker = "aarch64-linux-gnu-gcc"' | tee ~/.cargo/config.toml + echo 'env.BINDGEN_EXTRA_CLANG_ARGS_aarch64_unknown_linux_gnu = "-isystem /usr/aarch64-linux-gnu/include/ -ccc-gcc-name aarch64-linux-gnu-gcc"' | tee -a ~/.cargo/config.toml fi - name: Build Release run: | diff --git a/docs/installation.md b/docs/installation.md index c55903a07..49a9bd6e6 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -21,7 +21,7 @@ You can configure PostgreSQL by the reference of the parent image in https://hub ## Install from source -Install Rust and base dependency. +Install base dependency. ```sh sudo apt install -y \ @@ -41,10 +41,15 @@ sudo apt install -y \ ccache \ clang \ git +``` + +Install Rust. The following command will install Rustup, the Rust toolchain installer for your user. Do not install rustc using package manager. + +```sh curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh ``` -Install PostgreSQL. +Install PostgreSQL and its headers. We assume you may install PostgreSQL 15. Feel free to replace `15` to any other major version number you need. ```sh sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" >> /etc/apt/sources.list.d/pgdg.list' @@ -53,7 +58,7 @@ sudo apt-get update sudo apt-get -y install libpq-dev postgresql-15 postgresql-server-dev-15 ``` -Install clang-16. +Install clang-16. We do not support other versions of clang. ```sh sudo sh -c 'echo "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-16 main" >> /etc/apt/sources.list' @@ -62,7 +67,7 @@ sudo apt-get update sudo apt-get -y install clang-16 ``` -Clone the Repository. +Clone the Repository. Note the following commands are executed in the cloned repository directory. ```sh git clone https://github.com/tensorchord/pgvecto.rs.git @@ -101,6 +106,24 @@ DROP EXTENSION IF EXISTS vectors; CREATE EXTENSION vectors; ``` +### Cross compilation + +Assuming that you build target for aarch64 in a x86_64 host environment, you need to set right linker and sysroot for Rust. + +```sh +sudo apt install crossbuild-essential-arm64 +``` + +Add the following section to the end of `~/.cargo/config.toml`. + +```toml +[target.aarch64-unknown-linux-gnu] +linker = "aarch64-linux-gnu-gcc" + +[env] +BINDGEN_EXTRA_CLANG_ARGS_aarch64_unknown_linux_gnu = "-isystem /usr/aarch64-linux-gnu/include/ -ccc-gcc-name aarch64-linux-gnu-gcc" +``` + ## Install from release Download the deb package in the release page, and type `sudo apt install vectors-pg15-*.deb` to install the deb package. diff --git a/scripts/ci_setup.sh b/scripts/ci_setup.sh index 9e1b8d74f..f26050066 100755 --- a/scripts/ci_setup.sh +++ b/scripts/ci_setup.sh @@ -14,6 +14,8 @@ if [ "$OS" == "ubuntu-latest" ]; then sudo apt-get -y install build-essential libpq-dev postgresql-$VERSION postgresql-server-dev-$VERSION sudo apt-get -y install clang-16 sudo apt-get -y install crossbuild-essential-arm64 + echo 'target.aarch64-unknown-linux-gnu.linker = "aarch64-linux-gnu-gcc"' | tee ~/.cargo/config.toml + echo 'env.BINDGEN_EXTRA_CLANG_ARGS_aarch64_unknown_linux_gnu = "-isystem /usr/aarch64-linux-gnu/include/ -ccc-gcc-name aarch64-linux-gnu-gcc"' | tee -a ~/.cargo/config.toml echo "local all all trust" | sudo tee /etc/postgresql/$VERSION/main/pg_hba.conf echo "host all all 127.0.0.1/32 trust" | sudo tee -a /etc/postgresql/$VERSION/main/pg_hba.conf echo "host all all ::1/128 trust" | sudo tee -a /etc/postgresql/$VERSION/main/pg_hba.conf