Skip to content

Commit 0e4fff8

Browse files
authored
Try #81:
2 parents 7c13100 + 0faa5b8 commit 0e4fff8

File tree

4 files changed

+154
-30
lines changed

4 files changed

+154
-30
lines changed

.github/workflows/test.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
- proj-sys-ubuntu
1717
- proj-macos
1818
- proj-sys-macos
19+
- proj-sys-windows
1920
steps:
2021
- name: Mark the job as a success
2122
if: success()
@@ -119,3 +120,89 @@ jobs:
119120
uses: actions/checkout@v2
120121
- run: brew install proj
121122
- run: cargo test ${{ matrix.features }}
123+
124+
proj-sys-windows:
125+
name: proj-sys windows
126+
if: "!contains(github.event.head_commit.message, '[skip ci]')"
127+
runs-on: windows-latest
128+
env:
129+
_PROJ_SYS_TEST_EXPECT_BUILD_FROM_SRC: 0
130+
strategy:
131+
fail-fast: false
132+
matrix:
133+
config:
134+
- {
135+
target: "x86_64-pc-windows-msvc",
136+
VCPKG_DEFAULT_TRIPLET: "x64-windows-static",
137+
RUSTFLAGS: "-Ctarget-feature=+crt-static",
138+
features: "",
139+
}
140+
- {
141+
target: "x86_64-pc-windows-msvc",
142+
VCPKG_DEFAULT_TRIPLET: "x64-windows-static-md",
143+
features: "",
144+
}
145+
- {
146+
target: "x86_64-pc-windows-msvc",
147+
VCPKG_DEFAULT_TRIPLET: "x64-windows",
148+
VCPKGRS_DYNAMIC: 1,
149+
# "cargo test --doc" broken with dynamic lib on CI machine (missing dll)
150+
features: "--all-targets",
151+
}
152+
# - {
153+
# target: "i686-pc-windows-msvc",
154+
# VCPKG_DEFAULT_TRIPLET: "x86-windows-static",
155+
# RUSTFLAGS: "-Ctarget-feature=+crt-static",
156+
# features: "",
157+
# }
158+
# - {
159+
# target: "i686-pc-windows-msvc",
160+
# VCPKG_DEFAULT_TRIPLET: "x86-windows-static-md",
161+
# features: "",
162+
# }
163+
# - {
164+
# target: "i686-pc-windows-msvc",
165+
# VCPKG_DEFAULT_TRIPLET: "x86-windows",
166+
# VCPKGRS_DYNAMIC: 1,
167+
# features: "--all-targets",
168+
# }
169+
steps:
170+
- uses: actions/checkout@v2
171+
- name: Install vcpkg
172+
run: |
173+
git clone https://github.com/Microsoft/vcpkg.git vcp
174+
# PROJ version 7.2.1 - https://github.com/microsoft/vcpkg/search?q=proj4&type=commits
175+
git -C vcp checkout 8fe4184c6a17e237d8b864b6d10e0b520334a093
176+
vcp\bootstrap-vcpkg.bat -disableMetrics
177+
- name: Set env
178+
shell: bash
179+
run: echo "VCPKG_ROOT=${{ github.workspace }}\vcp" >> $GITHUB_ENV
180+
- name: Install LLVM and Clang
181+
uses: KyleMayes/install-llvm-action@v1
182+
with:
183+
version: "10.0"
184+
directory: ${{ runner.temp }}/llvm
185+
- name: Set LIBCLANG_PATH
186+
run: echo "LIBCLANG_PATH=$((gcm clang).source -replace "clang.exe")" >> $env:GITHUB_ENV
187+
- name: install proj lib
188+
env:
189+
VCPKG_DEFAULT_TRIPLET: "${{ matrix.config.VCPKG_DEFAULT_TRIPLET }}"
190+
shell: bash
191+
run: |
192+
set -ex
193+
echo VCPKG_ROOT=${VCPKG_ROOT}
194+
${VCPKG_ROOT}/vcpkg install proj
195+
- name: Run integration tests
196+
env:
197+
VCPKG_DEFAULT_TRIPLET: "${{ matrix.config.VCPKG_DEFAULT_TRIPLET }}"
198+
RUSTFLAGS: ${{ matrix.config.RUSTFLAGS }}
199+
shell: bash
200+
run: |
201+
set -ex
202+
rustup target add ${{ matrix.config.target }}
203+
rustc --version
204+
cargo --version
205+
echo dyn=${{ matrix.config.VCPKGRS_DYNAMIC }}
206+
if [ '${{ matrix.config.VCPKGRS_DYNAMIC }}' != '' ] ; then export VCPKGRS_DYNAMIC=1 ; fi
207+
cargo build --target ${{ matrix.config.target }} ${{ matrix.config.features }}
208+
cargo test --target ${{ matrix.config.target }} ${{ matrix.config.features }}

proj-sys/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ cmake = "0.1"
1919
flate2 = "1.0.14"
2020
tar = "0.4.26"
2121

22+
[target.'cfg(target_env = "msvc")'.build-dependencies]
23+
vcpkg = "0.2.11"
24+
winapi-build = "0.1.1"
25+
2226
[features]
2327
nobuild = []
2428
bundled_proj = []

proj-sys/build.rs

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,67 @@ use cmake;
33
use flate2::read::GzDecoder;
44
use std::fs::File;
55

6+
#[cfg(target_env = "msvc")]
7+
use vcpkg;
8+
#[cfg(target_env = "msvc")]
9+
use build;
610
use pkg_config;
711
use std::env;
812
use std::path::PathBuf;
913
use tar::Archive;
1014

1115
const MINIMUM_PROJ_VERSION: &str = "7.2.1";
1216

17+
#[cfg(target_env = "msvc")]
18+
fn try_vcpkg() -> Result<std::path::PathBuf, Box<dyn std::error::Error>> {
19+
build::link("shell32", true);
20+
build::link("ole32", true);
21+
let lib = vcpkg::Config::new()
22+
.emit_includes(true)
23+
.find_package("proj");
24+
25+
if let Err(_e) = lib {
26+
eprintln!("vcpkg proj library not found, trying pkg_config");
27+
return try_pkg_config()
28+
}
29+
30+
let include_path = lib.unwrap()
31+
.include_paths[0]
32+
.clone();
33+
34+
Ok(include_path)
35+
}
36+
37+
#[cfg(not(target_env = "msvc"))]
38+
fn try_vcpkg() -> Result<std::path::PathBuf, Box<dyn std::error::Error>> {
39+
try_pkg_config()
40+
}
41+
42+
fn try_pkg_config() -> Result<std::path::PathBuf, Box<dyn std::error::Error>> {
43+
pkg_config::Config::new()
44+
.atleast_version(MINIMUM_PROJ_VERSION)
45+
.probe("proj")
46+
.and_then(|pk| {
47+
eprintln!("found acceptable libproj already installed at: {:?}", pk.link_paths[0]);
48+
if let Ok(val) = &env::var("_PROJ_SYS_TEST_EXPECT_BUILD_FROM_SRC") {
49+
if val != "0" {
50+
panic!("for testing purposes: existing package was found, but should not have been");
51+
}
52+
}
53+
54+
// Tell cargo to tell rustc to link the system proj
55+
// shared library.
56+
println!("cargo:rustc-link-search=native={:?}", pk.link_paths[0]);
57+
println!("cargo:rustc-link-lib=proj");
58+
59+
Ok(pk.include_paths[0].clone())
60+
})
61+
.or_else(|err| {
62+
eprintln!("pkg-config unable to find existing libproj installation: {}", err);
63+
build_from_source()
64+
})
65+
}
66+
1367
#[cfg(feature = "nobuild")]
1468
fn main() {} // Skip the build script on docs.rs
1569

@@ -19,28 +73,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
1973
eprintln!("feature flags specified source build");
2074
build_from_source()?
2175
} else {
22-
pkg_config::Config::new()
23-
.atleast_version(MINIMUM_PROJ_VERSION)
24-
.probe("proj")
25-
.and_then(|pk| {
26-
eprintln!("found acceptable libproj already installed at: {:?}", pk.link_paths[0]);
27-
if let Ok(val) = &env::var("_PROJ_SYS_TEST_EXPECT_BUILD_FROM_SRC") {
28-
if val != "0" {
29-
panic!("for testing purposes: existing package was found, but should not have been");
30-
}
31-
}
32-
33-
// Tell cargo to tell rustc to link the system proj
34-
// shared library.
35-
println!("cargo:rustc-link-search=native={:?}", pk.link_paths[0]);
36-
println!("cargo:rustc-link-lib=proj");
37-
38-
Ok(pk.include_paths[0].clone())
39-
})
40-
.or_else(|err| {
41-
eprintln!("pkg-config unable to find existing libproj installation: {}", err);
42-
build_from_source()
43-
})?
76+
try_vcpkg()?
4477
};
4578

4679
// The bindgen::Builder is the main entry point

src/proj.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,8 +1036,8 @@ mod test {
10361036
let t = proj
10371037
.convert(MyPoint::new(4760096.421921, 3744293.729449))
10381038
.unwrap();
1039-
assert_relative_eq!(t.x(), 1450880.2910605003);
1040-
assert_relative_eq!(t.y(), 1141263.0111604529);
1039+
assert_relative_eq!(t.x(), 1450880.2910605003, epsilon = 1e-8);
1040+
assert_relative_eq!(t.y(), 1141263.0111604529, epsilon = 1e-8);
10411041
}
10421042
#[test]
10431043
// Carry out a projection from geodetic coordinates
@@ -1066,8 +1066,8 @@ mod test {
10661066
let t = stereo70
10671067
.project(MyPoint::new(500119.70352012233, 500027.77896348457), true)
10681068
.unwrap();
1069-
assert_relative_eq!(t.x(), 0.43633200013698786);
1070-
assert_relative_eq!(t.y(), 0.8028510000110507);
1069+
assert_relative_eq!(t.x(), 0.43633200013698786, epsilon = 1e-14);
1070+
assert_relative_eq!(t.y(), 0.8028510000110507, epsilon = 1e-14);
10711071
}
10721072
#[test]
10731073
// Carry out an inverse projection to geodetic coordinates
@@ -1159,8 +1159,8 @@ mod test {
11591159
MyPoint::new(4760197.421921, 3744394.729449),
11601160
];
11611161
ft_to_m.convert_array(&mut v).unwrap();
1162-
assert_relative_eq!(v[0].x(), 1450880.2910605003f64);
1163-
assert_relative_eq!(v[1].y(), 1141293.7960220198);
1162+
assert_relative_eq!(v[0].x(), 1450880.2910605003f64, epsilon = 1e-8);
1163+
assert_relative_eq!(v[1].y(), 1141293.7960220198, epsilon = 1e-8);
11641164
}
11651165

11661166
#[test]
@@ -1173,8 +1173,8 @@ mod test {
11731173
// 👽
11741174
let usa_m = MyPoint::new(-115.797615, 37.2647978);
11751175
let usa_ft = to_feet.convert(usa_m).unwrap();
1176-
assert_eq!(6693625.67217475, usa_ft.x());
1177-
assert_eq!(3497301.5918027186, usa_ft.y());
1176+
assert_relative_eq!(6693625.67217475, usa_ft.x(),epsilon = 1e-8);
1177+
assert_relative_eq!(3497301.5918027186, usa_ft.y(), epsilon = 1e-8);
11781178
}
11791179

11801180
#[test]

0 commit comments

Comments
 (0)