Skip to content

Commit e35a74a

Browse files
authored
fix cargo-pgrx and pgrx-tests on Windows (pgcentralfoundation#1934)
Notes: 1. postgres must run without administrator privileges, so switch calling `postgres` directly to starting postgres by `pg_ctl` in testing 2. Add Windows CI 3. known issue: `pgrx-cshim.c` is compiled with `-flto`, because, without this flag, `pgrx_embed.exe` is linked to `postgres.exe` 4. known issue: `cargo-pgrx` downloads, instead of building, postgres binaries from EDB website 5. known issue: `cargo pgrx run` and `cargo pgrx test` always print logs for `pg_ctl start` on Windows (pipes generated by `std::process::Command` are leaked to postgres, a command with `Stdio::piped()` hangs, so we use `Stdio::inherit()` on Windows) 6. breaking change: this pull request fixes `PgLwLock` and `PgAtomic` but introduces a breaking change about `PgLwLock` and `PgAtomic`: name must be provided at `PgLwLock/PgAtomic::new`, `PgLwLock::from_named` is removed and a parameter of `PgLwLock::attach` changes 7. breaking change: this pull request makes everything `C-unwind` and it's necessary for downstream to switch from `C` to `C-unwind` 8. regression: `cargo-pgrx` users need to execute `sudo sysctl fs.protected_fifos=0` before using `--runas` on Linux
1 parent a4708eb commit e35a74a

File tree

51 files changed

+1380
-505
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1380
-505
lines changed

.cargo/config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ r = "run --features"
77
[target.'cfg(target_os="macos")']
88
# Postgres symbols won't be available until runtime
99
rustflags = ["-Clink-arg=-Wl,-undefined,dynamic_lookup"]
10+
11+
[target.'cfg(target_env="msvc")']
12+
linker = "lld-link"

.github/workflows/runas.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,6 @@ jobs:
9393
run: cargo pgrx init --pg14=$(which pg_config)
9494

9595
- name: Test cargo pgrx test --runas
96-
run: cd pgrx-examples/arrays && cargo pgrx test pg14 --runas postgres --pgdata=/tmp/pgdata
96+
run: |
97+
echo 0 | sudo tee /proc/sys/fs/protected_fifos
98+
cd pgrx-examples/arrays && cargo pgrx test pg14 --runas postgres --pgdata=/tmp/pgdata

.github/workflows/tests.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,3 +579,78 @@ jobs:
579579

580580
- name: Stop sccache server
581581
run: sccache --stop-server || true
582+
583+
build_windows:
584+
name: Windows build & test
585+
needs: lintck
586+
runs-on: ${{ matrix.os }}
587+
if: "!contains(github.event.head_commit.message, 'nogha')"
588+
env:
589+
RUSTC_WRAPPER: sccache
590+
SCCACHE_DIR: C:\Users\runneradmin\sccache
591+
SCCACHE_IDLE_TIMEOUT: 0
592+
PG_VER: ${{ matrix.postgresql }}
593+
594+
strategy:
595+
matrix:
596+
os: [ "windows-2022" ]
597+
postgresql: [ 13, 17 ]
598+
599+
steps:
600+
- uses: actions/checkout@v4
601+
602+
- name: Set up prerequisites and environment
603+
run: |
604+
Write-Output ""
605+
606+
echo "----- Install sccache -----"
607+
Invoke-WebRequest -Uri "https://github.com/mozilla/sccache/releases/download/v0.5.4/sccache-v0.5.4-x86_64-pc-windows-msvc.tar.gz" -OutFile "sccache.tar.gz"
608+
tar -xzvf sccache.tar.gz
609+
Move-Item -Force "sccache-v0.5.4-x86_64-pc-windows-msvc\sccache.exe" -Destination "C:\Windows\System32"
610+
New-Item -ItemType Directory -Force -Path $env:SCCACHE_DIR | Out-Null
611+
sccache --version
612+
613+
rustup update
614+
615+
Write-Output "----- Outputting env -----"
616+
Get-ChildItem Env:
617+
Write-Output ""
618+
619+
620+
- name: Cache sccache directory
621+
uses: actions/cache@v4
622+
continue-on-error: false
623+
with:
624+
path: C:\Users\runneradmin\sccache
625+
key: pgrx-sccache-${{matrix.os}}-${{ hashFiles('**/Cargo.lock', '.github/workflows/tests.yml', '.cargo/config.toml') }}
626+
627+
- name: Cache cargo directory
628+
uses: actions/cache@v4
629+
with:
630+
path: |
631+
~/.cargo
632+
key: pgrx-cargo-${{matrix.os}}-tests-${{ hashFiles('**/Cargo.lock', '.github/workflows/tests.yml', '.cargo/config.toml') }}
633+
634+
- name: Start sccache server
635+
run: sccache --start-server
636+
637+
- name: Print sccache stats
638+
run: sccache --show-stats
639+
640+
- name: Install cargo-pgrx
641+
run: cargo install --path cargo-pgrx/ --debug --force
642+
643+
- name: Print sccache stats
644+
run: sccache --show-stats
645+
646+
- name: Run 'cargo pgrx init'
647+
run: cargo pgrx init --pg$env:PG_VER=download
648+
649+
- name: Run tests
650+
run: cargo test --all --no-default-features --features "pg$env:PG_VER pg_test cshim proptest" --all-targets
651+
652+
- name: Print sccache stats
653+
run: sccache --show-stats
654+
655+
- name: Stop sccache server
656+
run: sccache --stop-server || true

0 commit comments

Comments
 (0)