Skip to content

Commit f0e1151

Browse files
committed
v 0.1 发布
1 parent ed602cc commit f0e1151

File tree

5 files changed

+136
-87
lines changed

5 files changed

+136
-87
lines changed

build.rs

Lines changed: 106 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,64 +2,114 @@ extern crate cc;
22
use std::fs;
33
use std::process::{Command, Stdio};
44

5+
fn build_win_msvc() {
6+
cc::Build::new()
7+
.cpp(true)
8+
.flag("-Zi")
9+
.flag("-Gm")
10+
.flag("-INCREMENTAL")
11+
.warnings(false)
12+
.define("WIN32", None)
13+
.include("./src")
14+
.include("./src/osg")
15+
.file("./src/tileset.cpp")
16+
.file("./src/shp23dtile.cpp")
17+
.file("./src/osgb23dtile.cpp")
18+
.compile("3dtile");
19+
// -------------
20+
println!("cargo:rustc-link-search=native=./lib");
21+
// -------------
22+
println!("cargo:rustc-link-lib=gdal_i");
23+
println!("cargo:rustc-link-lib=osg");
24+
println!("cargo:rustc-link-lib=osgDB");
25+
println!("cargo:rustc-link-lib=osgUtil");
26+
27+
Command::new("cmd")
28+
.args(
29+
&["/C", "xcopy", r#".\bin"#, r#".\target\debug"#, "/y", "/e"],
30+
)
31+
.stdout(Stdio::inherit())
32+
.output()
33+
.unwrap();
34+
Command::new("cmd")
35+
.args(
36+
&["/C", "xcopy", r#".\bin"#, r#".\target\release"#, "/y", "/e"],
37+
)
38+
.stdout(Stdio::inherit())
39+
.output()
40+
.unwrap();
41+
}
42+
43+
fn build_win_gun() {
44+
cc::Build::new()
45+
.cpp(true)
46+
.flag("-std=c++11")
47+
.warnings(false)
48+
.define("WIN32", None)
49+
.include("./src")
50+
.include("./src/osg")
51+
.file("./src/tileset.cpp")
52+
.file("./src/shp23dtile.cpp")
53+
.file("./src/osgb23dtile.cpp")
54+
.compile("3dtile");
55+
// -------------
56+
println!("cargo:rustc-link-search=native=./lib");
57+
// -------------
58+
println!("cargo:rustc-link-lib=gdal_i");
59+
println!("cargo:rustc-link-lib=osg");
60+
println!("cargo:rustc-link-lib=osgDB");
61+
println!("cargo:rustc-link-lib=osgUtil");
62+
println!("cargo:rustc-link-lib=OpenThreads");
63+
64+
Command::new("cmd")
65+
.args(
66+
&["/C", "xcopy", r#".\bin"#, r#".\target\debug"#, "/y", "/e"],
67+
)
68+
.stdout(Stdio::inherit())
69+
.output()
70+
.unwrap();
71+
Command::new("cmd")
72+
.args(
73+
&["/C", "xcopy", r#".\bin"#, r#".\target\release"#, "/y", "/e"],
74+
)
75+
.stdout(Stdio::inherit())
76+
.output()
77+
.unwrap();
78+
}
79+
80+
fn build_linux_unkonw() {
81+
cc::Build::new()
82+
.cpp(true)
83+
.flag("-std=c++11")
84+
.warnings(false)
85+
.include("./src")
86+
.include("./src/osg")
87+
.file("./src/tileset.cpp")
88+
.file("./src/osgb23dtile.cpp")
89+
.compile("3dtile");
90+
// -------------
91+
println!("cargo:rustc-link-search=native=./lib");
92+
// -------------
93+
// println!("cargo:rustc-link-lib=gdal");
94+
println!("cargo:rustc-link-lib=OpenThreads");
95+
println!("cargo:rustc-link-lib=osg");
96+
println!("cargo:rustc-link-lib=osgDB");
97+
println!("cargo:rustc-link-lib=osgUtil");
98+
}
99+
5100
fn main() {
6101
fs::create_dir_all("target/debug").unwrap();
7102
fs::create_dir_all("target/release").unwrap();
8-
9-
if cfg!(windows) {
10-
cc::Build::new()
11-
.cpp(true)
12-
.flag("-Zi")
13-
.flag("-Gm")
14-
.flag("-INCREMENTAL")
15-
.warnings(false)
16-
.define("WIN32", None)
17-
.include("./src")
18-
.include("./src/osg")
19-
.file("./src/tileset.cpp")
20-
.file("./src/shp23dtile.cpp")
21-
.file("./src/osgb23dtile.cpp")
22-
.compile("3dtile");
23-
// -------------
24-
println!("cargo:rustc-link-search=native=./lib");
25-
// -------------
26-
println!("cargo:rustc-link-lib=gdal_i");
27-
println!("cargo:rustc-link-lib=osg");
28-
println!("cargo:rustc-link-lib=osgDB");
29-
println!("cargo:rustc-link-lib=osgUtil");
30-
31-
Command::new("cmd")
32-
.args(
33-
&["/C", "xcopy", r#".\bin"#, r#".\target\debug"#, "/y", "/e"],
34-
)
35-
.stdout(Stdio::inherit())
36-
.output()
37-
.unwrap();
38-
Command::new("cmd")
39-
.args(
40-
&["/C", "xcopy", r#".\bin"#, r#".\target\release"#, "/y", "/e"],
41-
)
42-
.stdout(Stdio::inherit())
43-
.output()
44-
.unwrap();
45-
} else {
46-
cc::Build::new()
47-
.cpp(true)
48-
.flag("-std=c++11")
49-
.warnings(false)
50-
.include("./src")
51-
.include("./src/osg")
52-
.file("./src/tileset.cpp")
53-
// .file("./src/shp23dtile.cpp")
54-
.file("./src/osgb23dtile.cpp")
55-
.compile("3dtile");
56-
// -------------
57-
println!("cargo:rustc-link-search=native=./lib");
58-
// -------------
59-
// println!("cargo:rustc-link-lib=gdal");
60-
println!("cargo:rustc-link-lib=OpenThreads");
61-
println!("cargo:rustc-link-lib=osg");
62-
println!("cargo:rustc-link-lib=osgDB");
63-
println!("cargo:rustc-link-lib=osgUtil");
103+
use std::env;
104+
match env::var("TARGET") {
105+
Ok(val) => {
106+
match val.as_str() {
107+
"x86_64-pc-windows-gnu" => build_win_gun(),
108+
"x86_64-unknown-linux-gnu" => build_linux_unkonw(),
109+
"x86_64-pc-windows-msvc" => build_win_msvc(),
110+
&_ => {}
111+
}
112+
}
113+
_ => {}
64114
}
65115
}

src/main.rs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,35 @@ use chrono::prelude::*;
1717
use log::{Level, LevelFilter};
1818

1919
fn main() {
20-
// use std::io;
21-
// let mut msg = String::new();
22-
// io::stdin().read_line(&mut msg).unwrap();
20+
// use std::io;
21+
// let mut msg = String::new();
22+
// io::stdin().read_line(&mut msg).unwrap();
2323
use std::env;
2424
if let Err(_) = env::var("RUST_LOG") {
2525
env::set_var("RUST_LOG", "info");
2626
}
2727
env::set_var("RUST_BACKTRACE", "1");
2828

2929
let mut builder = env_logger::Builder::from_default_env();
30-
builder.format(|buf, record| {
31-
let dt = Local::now();
32-
let mut style = buf.style();
33-
if record.level() <= Level::Error {
34-
style.set_color(env_logger::Color::Red);
35-
}
36-
else {
37-
style.set_color(env_logger::Color::Green);
38-
}
39-
writeln!(buf, "{}: {} - {}",
40-
style.value(record.level()),
41-
dt.format("%Y-%m-%d %H:%M:%S").to_string(),
42-
record.args())
30+
builder
31+
.format(|buf, record| {
32+
let dt = Local::now();
33+
let mut style = buf.style();
34+
if record.level() <= Level::Error {
35+
style.set_color(env_logger::Color::Red);
36+
} else {
37+
style.set_color(env_logger::Color::Green);
38+
}
39+
writeln!(
40+
buf,
41+
"{}: {} - {}",
42+
style.value(record.level()),
43+
dt.format("%Y-%m-%d %H:%M:%S").to_string(),
44+
record.args()
45+
)
4346
})
44-
.filter(None, LevelFilter::Info)
45-
.init();
47+
.filter(None, LevelFilter::Info)
48+
.init();
4649
//env_logger::init();
4750
let matches = App::new("Make 3dtile program")
4851
.version("1.0")

src/osgb.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,13 @@ pub fn osgb_batch_convert(
125125
);
126126
if out_ptr.is_null() {
127127
error!("failed: {}", path_clone.display());
128-
}
129-
else {
128+
} else {
130129
json_buf.resize(json_len as usize, 0);
131130
libc::memcpy(
132131
json_buf.as_mut_ptr() as *mut libc::c_void,
133-
out_ptr, json_len as usize
134-
);
132+
out_ptr,
133+
json_len as usize,
134+
);
135135
libc::free(out_ptr);
136136
}
137137
let t = TileResult {

src/shp23dtile.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,10 @@ extern "C" bool shp23dtile(const char* filename, int layer_id, const char* dest)
404404
}
405405

406406
OGREnvelope envelop;
407-
poLayer->GetExtent(&envelop);
407+
OGRErr err = poLayer->GetExtent(&envelop);
408+
if (err != OGRERR_NONE) {
409+
return false;
410+
}
408411

409412
bbox bound(envelop.MinX, envelop.MaxX, envelop.MinY, envelop.MaxY);
410413
node root(bound);

src/tiny_gltf.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -901,15 +901,8 @@ static void swap4(unsigned int *val) {
901901

902902
static bool FileExists(const std::string &abs_filename) {
903903
bool ret;
904-
#ifdef _WIN32
905-
FILE *fp;
906-
errno_t err = fopen_s(&fp, abs_filename.c_str(), "rb");
907-
if (err != 0) {
908-
return false;
909-
}
910-
#else
904+
911905
FILE *fp = fopen(abs_filename.c_str(), "rb");
912-
#endif
913906
if (fp) {
914907
ret = true;
915908
fclose(fp);

0 commit comments

Comments
 (0)