diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..b11351b --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +tests/data/* binary diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 37595ea..783c1ef 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,14 +11,17 @@ 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 + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 diff --git a/Cargo.lock b/Cargo.lock index fde4156..e4e5e80 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -393,9 +393,11 @@ name = "pg_query" version = "5.0.0" dependencies = [ "bindgen", + "cc", "clippy", "easy-parallel", "fs_extra", + "glob", "itertools", "pretty_assertions", "prost", diff --git a/Cargo.toml b/Cargo.toml index c73e21a..f8399ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/build.rs b/build.rs index 65765d0..9a68551 100644 --- a/build.rs +++ b/build.rs @@ -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}; @@ -12,12 +13,11 @@ static LIBRARY_NAME: &str = "pg_query"; fn main() -> Result<(), Box> { 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}"); @@ -35,18 +35,31 @@ fn main() -> Result<(), Box> { fs_extra::copy_items(&source_paths, &out_dir, ©_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 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("msvc") { + // Rust on Windows may not have "make" or "nmake" installed + cc::Build::new() + .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")) + .include(out_dir.join("./src/postgres/include/port/win32")) + .include(out_dir.join("./src/postgres/include/port/win32_msvc")) + .compile(LIBRARY_NAME); + } else { + 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 status = make.stdin(Stdio::null()).stdout(Stdio::inherit()).stderr(Stdio::inherit()).status()?; + if !status.success() { + return Err("libpg_query compilation failed".into()); + } } // Generate bindings for Rust diff --git a/libpg_query b/libpg_query index 2a00188..1ec3894 160000 --- a/libpg_query +++ b/libpg_query @@ -1 +1 @@ -Subproject commit 2a0018867c20011fc7166767083c05965241140b +Subproject commit 1ec38940e5c6f09a4c1d17a46d839a881c4f2db7