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

Windows support #39

Merged
merged 4 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tests/data/* binary
73 changes: 44 additions & 29 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,25 @@ name: Continuous integration
jobs:
ci:
env:
RUSTFLAGS: ${{ matrix.rust == 'nightly' && '-Z sanitizer=leak' || '' }}
runs-on: ubuntu-latest
RUSTFLAGS: ${{ matrix.rust == 'nightly' && matrix.os == 'ubuntu-latest' && '-Z sanitizer=leak' || '' }}
strategy:
fail-fast: false
matrix:
rust:
- stable
- nightly
os:
- ubuntu-latest
- windows-latest
include:
- rust: stable-x86_64-pc-windows-gnu
os: windows-latest
- rust: stable-i686-pc-windows-msvc
os: windows-latest
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: recursive

Expand All @@ -31,39 +39,51 @@ jobs:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-${{ matrix.backend }}-cargo-${{ hashFiles('**/Cargo.toml') }}
key: ${{ matrix.os }}-${{ matrix.rust }}-cargo-${{ hashFiles('**/Cargo.toml') }}

- name: Install rustup if needed
run: |
if ! command -v rustup &>/dev/null; then
curl --proto '=https' --tlsv1.2 --retry 10 --retry-connrefused --location --silent --show-error --fail "https://sh.rustup.rs" | sh -s -- --default-toolchain none -y
echo "${CARGO_HOME:-$HOME/.cargo}/bin" >> $GITHUB_PATH
fi
if: runner.os != 'Windows'
shell: bash

- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
run: rustup toolchain install ${{ matrix.rust }} --profile minimal --no-self-update
shell: bash

- name: Default to nightly if requested
run: rustup default nightly
if: matrix.rust == 'nightly'

- name: Build pg_query
uses: actions-rs/cargo@v1
with:
command: build
run: cargo build

- name: Run tests
uses: actions-rs/cargo@v1
with:
command: test
run: cargo test

check_style:
name: Check file formatting and style
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: recursive

- uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
components: clippy, rustfmt
override: true
- name: Install rustup if needed
run: |
if ! command -v rustup &>/dev/null; then
curl --proto '=https' --tlsv1.2 --retry 10 --retry-connrefused --location --silent --show-error --fail "https://sh.rustup.rs" | sh -s -- --default-toolchain none -y
echo "${CARGO_HOME:-$HOME/.cargo}/bin" >> $GITHUB_PATH
fi
if: runner.os != 'Windows'
shell: bash

- name: Install toolchain
run: rustup toolchain install stable --component clippy --component rustfmt --profile minimal --no-self-update
shell: bash

- name: Cache cargo registry
uses: actions/cache@v2
Expand All @@ -74,12 +94,7 @@ jobs:
key: clippy-cargo-${{ hashFiles('**/Cargo.toml') }}

- name: Check file formatting
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
run: cargo fmt --all -- --check

- name: Run clippy
uses: actions-rs/cargo@v1
with:
command: clippy
run: cargo clippy
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ bindgen = "0.66.1"
clippy = { version = "0.0.302", optional = true }
prost-build = "0.10.4"
fs_extra = "1.2.0"
cc = "1.0.83"
glob = "0.3.1"

[dev-dependencies]
easy-parallel = "3.2.0"
Expand Down
35 changes: 22 additions & 13 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![cfg_attr(feature = "clippy", plugin(clippy))]

use fs_extra::dir::CopyOptions;
use glob::glob;
use std::env;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
Expand All @@ -12,12 +13,11 @@ static LIBRARY_NAME: &str = "pg_query";
fn main() -> Result<(), Box<dyn std::error::Error>> {
let out_dir = PathBuf::from(env::var("OUT_DIR")?);
let build_path = Path::new(".").join(SOURCE_DIRECTORY);
let makefile_path = build_path.join("Makefile");
let out_header_path = out_dir.join(LIBRARY_NAME).with_extension("h");
let out_protobuf_path = out_dir.join("protobuf");
let target = env::var("TARGET").unwrap();

// Configure cargo through stdout
println!("cargo:rerun-if-changed={}", makefile_path.display()); // Includes version number
println!("cargo:rustc-link-search=native={}", out_dir.display());
println!("cargo:rustc-link-lib=static={LIBRARY_NAME}");

Expand All @@ -35,19 +35,28 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
fs_extra::copy_items(&source_paths, &out_dir, &copy_options)?;

// Compile the C library.
let mut make = Command::new("make");

make.env_remove("PROFILE").arg("-C").arg(&out_dir).arg("build");

if env::var("PROFILE").unwrap() == "debug" {
make.arg("DEBUG=1");
let mut build = cc::Build::new();
build
.files(glob(out_dir.join("src/*.c").to_str().unwrap()).unwrap().map(|p| p.unwrap()))
.files(glob(out_dir.join("src/postgres/*.c").to_str().unwrap()).unwrap().map(|p| p.unwrap()))
.file(out_dir.join("vendor/protobuf-c/protobuf-c.c"))
.file(out_dir.join("vendor/xxhash/xxhash.c"))
.file(out_dir.join("protobuf/pg_query.pb-c.c"))
.include(out_dir.join("."))
.include(out_dir.join("./vendor"))
.include(out_dir.join("./src/postgres/include"))
.include(out_dir.join("./src/include"))
.warnings(false); // Avoid unnecessary warnings, as they are already considered as part of libpg_query development
if env::var("PROFILE").unwrap() == "debug" || env::var("DEBUG").unwrap() == "1" {
build.define("USE_ASSERT_CHECKING", None);
}

let status = make.stdin(Stdio::null()).stdout(Stdio::inherit()).stderr(Stdio::inherit()).status()?;

if !status.success() {
return Err("libpg_query compilation failed".into());
if target.contains("windows") {
build.include(out_dir.join("./src/postgres/include/port/win32"));
if target.contains("msvc") {
build.include(out_dir.join("./src/postgres/include/port/win32_msvc"));
}
}
build.compile(LIBRARY_NAME);

// Generate bindings for Rust
bindgen::Builder::default()
Expand Down
2 changes: 1 addition & 1 deletion libpg_query
Submodule libpg_query updated 90 files
+1 −0 .gitattributes
+38 −1 .github/workflows/ci.yml
+4 −0 .gitignore
+18 −0 CHANGELOG.md
+37 −37 Makefile
+108 −0 Makefile.msvc
+6 −0 README.md
+1 −1 examples/scan.c
+1 −1 protobuf/pg_query.proto
+65 −13 scripts/extract_source.rb
+16 −3 scripts/generate_fingerprint_outfuncs.rb
+11 −6 scripts/generate_protobuf_and_funcs.rb
+149 −0 scripts/pg_config_overrides.h
+0 −0 src/include/pg_query_enum_defs.c
+0 −0 src/include/pg_query_fingerprint_conds.c
+1 −1 src/include/pg_query_fingerprint_defs.c
+0 −0 src/include/pg_query_json_helper.c
+0 −0 src/include/pg_query_outfuncs_conds.c
+1 −1 src/include/pg_query_outfuncs_defs.c
+0 −0 src/include/pg_query_readfuncs_conds.c
+1 −1 src/include/pg_query_readfuncs_defs.c
+9 −0 src/pg_query.c
+4 −5 src/pg_query_fingerprint.c
+6 −0 src/pg_query_outfuncs_json.c
+1 −0 src/pg_query_outfuncs_protobuf.c
+1 −0 src/pg_query_outfuncs_protobuf_cpp.cc
+1 −1 src/pg_query_parse.c
+6 −4 src/pg_query_parse_plpgsql.c
+1 −0 src/pg_query_readfuncs_protobuf.c
+1 −1 src/pg_query_split.c
+0 −0 src/postgres/guc-file.c
+0 −33 src/postgres/include/common/ip.h
+1 −1 src/postgres/include/miscadmin.h
+1 −1 src/postgres/include/nodes/nodes.h
+3 −3 src/postgres/include/parser/parser.h
+136 −2 src/postgres/include/pg_config.h
+7 −7 src/postgres/include/pg_config_os.h
+1 −1 src/postgres/include/pgstat.h
+2 −2 src/postgres/include/pl_gram.h
+11 −11 src/postgres/include/plpgsql.h
+17 −0 src/postgres/include/port/atomics/arch-hppa.h
+101 −0 src/postgres/include/port/atomics/generic-msvc.h
+106 −0 src/postgres/include/port/atomics/generic-sunpro.h
+59 −0 src/postgres/include/port/win32.h
+3 −0 src/postgres/include/port/win32/arpa/inet.h
+1 −0 src/postgres/include/port/win32/dlfcn.h
+1 −0 src/postgres/include/port/win32/grp.h
+7 −0 src/postgres/include/port/win32/netdb.h
+3 −0 src/postgres/include/port/win32/netinet/in.h
+7 −0 src/postgres/include/port/win32/netinet/tcp.h
+3 −0 src/postgres/include/port/win32/pwd.h
+20 −0 src/postgres/include/port/win32/sys/resource.h
+3 −0 src/postgres/include/port/win32/sys/select.h
+26 −0 src/postgres/include/port/win32/sys/socket.h
+17 −0 src/postgres/include/port/win32/sys/un.h
+3 −0 src/postgres/include/port/win32/sys/wait.h
+34 −0 src/postgres/include/port/win32_msvc/dirent.h
+1 −0 src/postgres/include/port/win32_msvc/sys/file.h
+1 −0 src/postgres/include/port/win32_msvc/sys/param.h
+1 −0 src/postgres/include/port/win32_msvc/sys/time.h
+9 −0 src/postgres/include/port/win32_msvc/unistd.h
+3 −0 src/postgres/include/port/win32_msvc/utime.h
+594 −0 src/postgres/include/port/win32_port.h
+0 −20 src/postgres/include/postmaster/auxprocess.h
+0 −17 src/postgres/include/postmaster/fork_process.h
+1 −1 src/postgres/include/postmaster/postmaster.h
+1 −1 src/postgres/include/storage/ipc.h
+2 −2 src/postgres/include/tcop/tcopprot.h
+1 −1 src/postgres/include/utils/builtins.h
+3 −3 src/postgres/include/utils/elog.h
+4 −4 src/postgres/include/utils/guc.h
+2 −2 src/postgres/include/utils/memutils.h
+1 −1 src/postgres/include/utils/palloc.h
+0 −56 src/postgres/include/utils/pidfile.h
+0 −5,321 src/postgres/src_backend_nodes_copyfuncs.funcs.c
+0 −3,354 src/postgres/src_backend_nodes_equalfuncs.funcs.c
+38 −0 src/postgres/src_backend_nodes_nodes.c
+0 −2,220 src/postgres/src_backend_postmaster_postmaster.c
+17 −152 src/postgres/src_backend_utils_error_elog.c
+1 −1 src/postgres/src_backend_utils_init_globals.c
+8 −63 src/postgres/src_backend_utils_mb_mbutils.c
+0 −2 src/postgres/src_backend_utils_misc_guc_tables.c
+78 −4 src/postgres/src_port_pg_bitutils.c
+3 −3 src/postgres/src_port_snprintf.c
+79 −0 src/postgres/src_port_strlcpy.c
+0 −39 src/postgres/src_port_strnlen.c
+9 −5 test/deparse.c
+3 −1 test/fingerprint_tests.c
+6 −5 test/parse_plpgsql.c
+8 −10 test/split.c
Loading