Skip to content

Commit

Permalink
v 0.1 发布
Browse files Browse the repository at this point in the history
  • Loading branch information
fanvanzh committed Apr 12, 2018
1 parent ed602cc commit f0e1151
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 87 deletions.
162 changes: 106 additions & 56 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,114 @@ extern crate cc;
use std::fs;
use std::process::{Command, Stdio};

fn build_win_msvc() {
cc::Build::new()
.cpp(true)
.flag("-Zi")
.flag("-Gm")
.flag("-INCREMENTAL")
.warnings(false)
.define("WIN32", None)
.include("./src")
.include("./src/osg")
.file("./src/tileset.cpp")
.file("./src/shp23dtile.cpp")
.file("./src/osgb23dtile.cpp")
.compile("3dtile");
// -------------
println!("cargo:rustc-link-search=native=./lib");
// -------------
println!("cargo:rustc-link-lib=gdal_i");
println!("cargo:rustc-link-lib=osg");
println!("cargo:rustc-link-lib=osgDB");
println!("cargo:rustc-link-lib=osgUtil");

Command::new("cmd")
.args(
&["/C", "xcopy", r#".\bin"#, r#".\target\debug"#, "/y", "/e"],
)
.stdout(Stdio::inherit())
.output()
.unwrap();
Command::new("cmd")
.args(
&["/C", "xcopy", r#".\bin"#, r#".\target\release"#, "/y", "/e"],
)
.stdout(Stdio::inherit())
.output()
.unwrap();
}

fn build_win_gun() {
cc::Build::new()
.cpp(true)
.flag("-std=c++11")
.warnings(false)
.define("WIN32", None)
.include("./src")
.include("./src/osg")
.file("./src/tileset.cpp")
.file("./src/shp23dtile.cpp")
.file("./src/osgb23dtile.cpp")
.compile("3dtile");
// -------------
println!("cargo:rustc-link-search=native=./lib");
// -------------
println!("cargo:rustc-link-lib=gdal_i");
println!("cargo:rustc-link-lib=osg");
println!("cargo:rustc-link-lib=osgDB");
println!("cargo:rustc-link-lib=osgUtil");
println!("cargo:rustc-link-lib=OpenThreads");

Command::new("cmd")
.args(
&["/C", "xcopy", r#".\bin"#, r#".\target\debug"#, "/y", "/e"],
)
.stdout(Stdio::inherit())
.output()
.unwrap();
Command::new("cmd")
.args(
&["/C", "xcopy", r#".\bin"#, r#".\target\release"#, "/y", "/e"],
)
.stdout(Stdio::inherit())
.output()
.unwrap();
}

fn build_linux_unkonw() {
cc::Build::new()
.cpp(true)
.flag("-std=c++11")
.warnings(false)
.include("./src")
.include("./src/osg")
.file("./src/tileset.cpp")
.file("./src/osgb23dtile.cpp")
.compile("3dtile");
// -------------
println!("cargo:rustc-link-search=native=./lib");
// -------------
// println!("cargo:rustc-link-lib=gdal");
println!("cargo:rustc-link-lib=OpenThreads");
println!("cargo:rustc-link-lib=osg");
println!("cargo:rustc-link-lib=osgDB");
println!("cargo:rustc-link-lib=osgUtil");
}

fn main() {
fs::create_dir_all("target/debug").unwrap();
fs::create_dir_all("target/release").unwrap();

if cfg!(windows) {
cc::Build::new()
.cpp(true)
.flag("-Zi")
.flag("-Gm")
.flag("-INCREMENTAL")
.warnings(false)
.define("WIN32", None)
.include("./src")
.include("./src/osg")
.file("./src/tileset.cpp")
.file("./src/shp23dtile.cpp")
.file("./src/osgb23dtile.cpp")
.compile("3dtile");
// -------------
println!("cargo:rustc-link-search=native=./lib");
// -------------
println!("cargo:rustc-link-lib=gdal_i");
println!("cargo:rustc-link-lib=osg");
println!("cargo:rustc-link-lib=osgDB");
println!("cargo:rustc-link-lib=osgUtil");

Command::new("cmd")
.args(
&["/C", "xcopy", r#".\bin"#, r#".\target\debug"#, "/y", "/e"],
)
.stdout(Stdio::inherit())
.output()
.unwrap();
Command::new("cmd")
.args(
&["/C", "xcopy", r#".\bin"#, r#".\target\release"#, "/y", "/e"],
)
.stdout(Stdio::inherit())
.output()
.unwrap();
} else {
cc::Build::new()
.cpp(true)
.flag("-std=c++11")
.warnings(false)
.include("./src")
.include("./src/osg")
.file("./src/tileset.cpp")
// .file("./src/shp23dtile.cpp")
.file("./src/osgb23dtile.cpp")
.compile("3dtile");
// -------------
println!("cargo:rustc-link-search=native=./lib");
// -------------
// println!("cargo:rustc-link-lib=gdal");
println!("cargo:rustc-link-lib=OpenThreads");
println!("cargo:rustc-link-lib=osg");
println!("cargo:rustc-link-lib=osgDB");
println!("cargo:rustc-link-lib=osgUtil");
use std::env;
match env::var("TARGET") {
Ok(val) => {
match val.as_str() {
"x86_64-pc-windows-gnu" => build_win_gun(),
"x86_64-unknown-linux-gnu" => build_linux_unkonw(),
"x86_64-pc-windows-msvc" => build_win_msvc(),
&_ => {}
}
}
_ => {}
}
}
39 changes: 21 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,35 @@ use chrono::prelude::*;
use log::{Level, LevelFilter};

fn main() {
// use std::io;
// let mut msg = String::new();
// io::stdin().read_line(&mut msg).unwrap();
// use std::io;
// let mut msg = String::new();
// io::stdin().read_line(&mut msg).unwrap();
use std::env;
if let Err(_) = env::var("RUST_LOG") {
env::set_var("RUST_LOG", "info");
}
env::set_var("RUST_BACKTRACE", "1");

let mut builder = env_logger::Builder::from_default_env();
builder.format(|buf, record| {
let dt = Local::now();
let mut style = buf.style();
if record.level() <= Level::Error {
style.set_color(env_logger::Color::Red);
}
else {
style.set_color(env_logger::Color::Green);
}
writeln!(buf, "{}: {} - {}",
style.value(record.level()),
dt.format("%Y-%m-%d %H:%M:%S").to_string(),
record.args())
builder
.format(|buf, record| {
let dt = Local::now();
let mut style = buf.style();
if record.level() <= Level::Error {
style.set_color(env_logger::Color::Red);
} else {
style.set_color(env_logger::Color::Green);
}
writeln!(
buf,
"{}: {} - {}",
style.value(record.level()),
dt.format("%Y-%m-%d %H:%M:%S").to_string(),
record.args()
)
})
.filter(None, LevelFilter::Info)
.init();
.filter(None, LevelFilter::Info)
.init();
//env_logger::init();
let matches = App::new("Make 3dtile program")
.version("1.0")
Expand Down
8 changes: 4 additions & 4 deletions src/osgb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ pub fn osgb_batch_convert(
);
if out_ptr.is_null() {
error!("failed: {}", path_clone.display());
}
else {
} else {
json_buf.resize(json_len as usize, 0);
libc::memcpy(
json_buf.as_mut_ptr() as *mut libc::c_void,
out_ptr, json_len as usize
);
out_ptr,
json_len as usize,
);
libc::free(out_ptr);
}
let t = TileResult {
Expand Down
5 changes: 4 additions & 1 deletion src/shp23dtile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,10 @@ extern "C" bool shp23dtile(const char* filename, int layer_id, const char* dest)
}

OGREnvelope envelop;
poLayer->GetExtent(&envelop);
OGRErr err = poLayer->GetExtent(&envelop);
if (err != OGRERR_NONE) {
return false;
}

bbox bound(envelop.MinX, envelop.MaxX, envelop.MinY, envelop.MaxY);
node root(bound);
Expand Down
9 changes: 1 addition & 8 deletions src/tiny_gltf.h
Original file line number Diff line number Diff line change
Expand Up @@ -901,15 +901,8 @@ static void swap4(unsigned int *val) {

static bool FileExists(const std::string &abs_filename) {
bool ret;
#ifdef _WIN32
FILE *fp;
errno_t err = fopen_s(&fp, abs_filename.c_str(), "rb");
if (err != 0) {
return false;
}
#else

FILE *fp = fopen(abs_filename.c_str(), "rb");
#endif
if (fp) {
ret = true;
fclose(fp);
Expand Down

0 comments on commit f0e1151

Please sign in to comment.