Skip to content

Commit

Permalink
new path overrides, qt_core works!
Browse files Browse the repository at this point in the history
  • Loading branch information
Riateche committed Jan 13, 2017
1 parent 0f27e64 commit 99df09e
Show file tree
Hide file tree
Showing 43 changed files with 519 additions and 396 deletions.
65 changes: 29 additions & 36 deletions cpp_to_rust/cpp_to_rust_build_tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ pub struct Config {
}

fn manifest_dir() -> Result<PathBuf> {
let dir = std::env::var("CARGO_MANIFEST_DIR").chain_err(|| "CARGO_MANIFEST_DIR env var is missing")?;
let dir =
std::env::var("CARGO_MANIFEST_DIR").chain_err(|| "CARGO_MANIFEST_DIR env var is missing")?;
Ok(PathBuf::from(dir))
}
fn out_dir() -> Result<PathBuf> {
Expand Down Expand Up @@ -64,43 +65,37 @@ impl Config {
cmake_vars.push(CMakeVar::new("C2R_LIBRARY_TYPE",
match cpp_build_config_data.library_type() {
Some(CppLibraryType::Shared) => "SHARED",
Some(CppLibraryType::Static) | None => "STATIC",
Some(CppLibraryType::Static) |
None => "STATIC",
}));
cmake_vars.push(CMakeVar::new_path_list(
"C2R_INCLUDE_PATHS",
self.cpp_build_paths.include_paths())?);
cmake_vars.push(CMakeVar::new_path_list(
"C2R_LIB_PATHS",
self.cpp_build_paths.lib_paths())?);
cmake_vars.push(CMakeVar::new_path_list(
"C2R_FRAMEWORK_PATHS",
self.cpp_build_paths.framework_paths())?);
cmake_vars.push(CMakeVar::new_list(
"C2R_LINKED_LIBS",
cpp_build_config_data.linked_libs())?);
cmake_vars.push(CMakeVar::new_list(
"C2R_LINKED_FRAMEWORKS",
cpp_build_config_data.linked_frameworks())?);
cmake_vars.push(CMakeVar::new(
"C2R_COMPILER_FLAGS",
cpp_build_config_data.compiler_flags().join(" ")));
cmake_vars.push(CMakeVar::new_path_list("C2R_LIB_PATHS", self.cpp_build_paths.lib_paths())?);
cmake_vars.push(CMakeVar::new_path_list("C2R_FRAMEWORK_PATHS",
self.cpp_build_paths.framework_paths())?);
cmake_vars.push(CMakeVar::new_list("C2R_LINKED_LIBS", cpp_build_config_data.linked_libs())?);
cmake_vars.push(CMakeVar::new_list("C2R_LINKED_FRAMEWORKS",
cpp_build_config_data.linked_frameworks())?);
cmake_vars.push(CMakeVar::new("C2R_COMPILER_FLAGS",
cpp_build_config_data.compiler_flags().join(" ")));
let out_dir = out_dir()?;
let c_lib_install_dir = out_dir.with_added("c_lib_install");
let manifest_dir = manifest_dir()?;
let profile = std::env::var("PROFILE").chain_err(|| "PROFILE env var is missing")?;
CppLibBuilder {
cmake_source_dir: manifest_dir.with_added("c_lib"),
build_dir: out_dir.with_added("c_lib_build"),
install_dir: c_lib_install_dir.clone(),
num_jobs: std::env::var("NUM_JOBS").ok().and_then(|x| x.parse().ok()),
pipe_output: false,
cmake_vars: cmake_vars,
build_type: match profile.as_str() {
"debug" => BuildType::Debug,
"release" => BuildType::Release,
_ => return Err(format!("unknown value of PROFILE env var: {}", profile).into()),
}
}.run()?;
cmake_source_dir: manifest_dir.with_added("c_lib"),
build_dir: out_dir.with_added("c_lib_build"),
install_dir: c_lib_install_dir.clone(),
num_jobs: std::env::var("NUM_JOBS").ok().and_then(|x| x.parse().ok()),
pipe_output: false,
cmake_vars: cmake_vars,
build_type: match profile.as_str() {
"debug" => BuildType::Debug,
"release" => BuildType::Release,
_ => return Err(format!("unknown value of PROFILE env var: {}", profile).into()),
},
}.run()?;
{
let mut ffi_file = create_file(out_dir.with_added("ffi.rs"))?;
for name in cpp_build_config_data.linked_libs() {
Expand All @@ -115,19 +110,17 @@ impl Config {
}
if cpp_build_config_data.library_type() == Some(CppLibraryType::Shared) {
ffi_file.write(format!("#[link(name = \"{}\")]\n",
&build_script_data.cpp_wrapper_lib_name))?;
&build_script_data.cpp_wrapper_lib_name))?;
} else {
ffi_file.write(format!("#[link(name = \"{}\", kind = \"static\")]\n",
&build_script_data.cpp_wrapper_lib_name))?;
&build_script_data.cpp_wrapper_lib_name))?;
}
ffi_file.write(
file_to_string(manifest_dir.with_added("src").with_added("ffi.in.rs"))?)?;
ffi_file.write(file_to_string(manifest_dir.with_added("src").with_added("ffi.in.rs"))?)?;
}
{

let mut command = Command::new(c_lib_install_dir
.with_added("lib")
.with_added(format!("type_sizes{}", exe_suffix())));
let mut command = Command::new(c_lib_install_dir.with_added("lib")
.with_added(format!("type_sizes{}", exe_suffix())));
let mut file = create_file(out_dir.with_added("type_sizes.rs"))?;
file.write(run_command(&mut command, true, true)?)?;
}
Expand Down
2 changes: 1 addition & 1 deletion cpp_to_rust/cpp_to_rust_common/src/build_script_data.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub use serializable::{BuildScriptData};
pub use serializable::BuildScriptData;
7 changes: 3 additions & 4 deletions cpp_to_rust/cpp_to_rust_common/src/cargo_override.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ pub fn set_cargo_override<P1: AsRef<Path>, P: AsRef<Path>>(cargo_toml_location:
.chain_err(|| "no 'package.version' in Cargo.toml")?;
let key = format!("{}:{}",
name.as_str()
.chain_err(|| "'package.name' must be a string")?,
.chain_err(|| "'package.name' must be a string")?,
version.as_str()
.chain_err(|| "'package.version' must be a string")?);
.chain_err(|| "'package.version' must be a string")?);
let mut value = toml::Table::new();
value.insert("path".to_string(),
toml::Value::String(path_to_str(path.as_ref())?.to_string()));
table.insert(key,
toml::Value::Table(value));
table.insert(key, toml::Value::Table(value));
}
table
}));
Expand Down
47 changes: 28 additions & 19 deletions cpp_to_rust/cpp_to_rust_common/src/cpp_lib_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,40 @@ impl CMakeVar {
}
}
pub fn new_list<I, S, L>(name: S, paths: L) -> Result<CMakeVar>
where S: Into<String>, I: AsRef<str>, L: IntoIterator<Item=I>
where S: Into<String>,
I: AsRef<str>,
L: IntoIterator<Item = I>
{
let value = paths.into_iter().map_if_ok(|s| -> Result<_> {
if s.as_ref().contains(';') {
Err(format!("can't pass value to cmake because ';' symbol is reserved: {}", s.as_ref()).into())
} else {
Ok(s)
}
})?.into_iter().join(";");
let value = paths.into_iter()
.map_if_ok(|s| -> Result<_> {
if s.as_ref().contains(';') {
Err(format!("can't pass value to cmake because ';' symbol is reserved: {}",
s.as_ref())
.into())
} else {
Ok(s)
}
})?
.into_iter()
.join(";");
Ok(CMakeVar::new(name, value))
}

pub fn new_path_list<I, S, L>(name: S, paths: L) -> Result<CMakeVar>
where S: Into<String>, I: AsRef<Path>, L: IntoIterator<Item=I>
where S: Into<String>,
I: AsRef<Path>,
L: IntoIterator<Item = I>
{
CMakeVar::new_list(name, paths.into_iter().map_if_ok(|x| {
path_to_str(x.as_ref()).map(|x| x.to_string())
})?)
CMakeVar::new_list(name,
paths.into_iter()
.map_if_ok(|x| path_to_str(x.as_ref()).map(|x| x.to_string()))?)
}
}

#[derive(Debug, Clone)]
pub enum BuildType {
Debug,
Release
Release,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -76,12 +85,12 @@ impl CppLibBuilder {
cmake_command.arg("-G").arg("NMake Makefiles");
}
let mut actual_cmake_vars = self.cmake_vars.clone();
actual_cmake_vars.push(CMakeVar::new("CMAKE_BUILD_TYPE", match actual_build_type {
BuildType::Release => "Release",
BuildType::Debug => "Debug",
}));
actual_cmake_vars.push(CMakeVar::new("CMAKE_INSTALL_PREFIX",
path_to_str(&self.install_dir)?));
actual_cmake_vars.push(CMakeVar::new("CMAKE_BUILD_TYPE",
match actual_build_type {
BuildType::Release => "Release",
BuildType::Debug => "Debug",
}));
actual_cmake_vars.push(CMakeVar::new("CMAKE_INSTALL_PREFIX", path_to_str(&self.install_dir)?));

for var in actual_cmake_vars {
cmake_command.arg(format!("-D{}={}", var.name, var.value));
Expand Down
8 changes: 2 additions & 6 deletions cpp_to_rust/cpp_to_rust_common/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,8 @@ impl Error {
if let Some(path) = symbol.filename() {
if path.components().any(|x| {
if let Some(x) = x.as_os_str().to_str() {
x == "libstd" ||
x == "libpanic_unwind" ||
x == "libcore" ||
x == "errors.rs" ||
x.starts_with("backtrace") ||
x.starts_with("error-chain")
x == "libstd" || x == "libpanic_unwind" || x == "libcore" || x == "errors.rs" ||
x.starts_with("backtrace") || x.starts_with("error-chain")
} else {
false
}
Expand Down
31 changes: 21 additions & 10 deletions cpp_to_rust/cpp_to_rust_common/src/file_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,8 @@ pub fn load_toml<P: AsRef<Path>>(path: P) -> Result<toml::Table> {

pub fn save_toml<P: AsRef<Path>>(path: P, data: toml::Table) -> Result<()> {
let mut file = create_file(path.as_ref())?;
file.write(toml::Value::Table(data).to_string()).chain_err(|| {
format!("failed to write to TOML file: {}",
path.as_ref().display())
})
file.write(toml::Value::Table(data).to_string())
.chain_err(|| format!("failed to write to TOML file: {}", path.as_ref().display()))
}


Expand All @@ -158,10 +156,12 @@ pub fn create_file<P: AsRef<Path>>(path: P) -> Result<FileWrapper> {
})
}

pub fn open_file_with_options<P: AsRef<Path>>(path: P, options: &fs::OpenOptions) -> Result<FileWrapper> {
pub fn open_file_with_options<P: AsRef<Path>>(path: P,
options: &fs::OpenOptions)
-> Result<FileWrapper> {
Ok(FileWrapper {
file: options.open(path.as_ref())
.chain_err(|| format!("Failed to open file: {:?}", path.as_ref()))?,
.chain_err(|| format!("Failed to open file: {:?}", path.as_ref()))?,
path: path.as_ref().to_path_buf(),
})
}
Expand All @@ -170,8 +170,8 @@ impl FileWrapper {
pub fn read_all(&mut self) -> Result<String> {
let mut r = String::new();
self.file
.read_to_string(&mut r)
.chain_err(|| format!("Failed to read from file: {:?}", self.path))?;
.read_to_string(&mut r)
.chain_err(|| format!("Failed to read from file: {:?}", self.path))?;
Ok(r)
}

Expand Down Expand Up @@ -233,8 +233,8 @@ pub struct ReadDirWrapper {

pub fn read_dir<P: AsRef<Path>>(path: P) -> Result<ReadDirWrapper> {
Ok(ReadDirWrapper {
read_dir: fs::read_dir(path.as_ref())
.chain_err(|| format!("Failed to read dir: {:?}", path.as_ref()))?,
read_dir:
fs::read_dir(path.as_ref()).chain_err(|| format!("Failed to read dir: {:?}", path.as_ref()))?,
path: path.as_ref().to_path_buf(),
})
}
Expand Down Expand Up @@ -273,3 +273,14 @@ pub fn os_string_into_string(s: OsString) -> Result<String> {
s.into_string()
.map_err(|s| format!("String is not valid unicode: {}", s.to_string_lossy()).into())
}

pub fn repo_crate_local_path(relative_path: &str) -> Result<PathBuf> {
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let parent = path.parent().chain_err(|| "failed to get parent directory")?;
let parent2 = parent.parent().chain_err(|| "failed to get parent directory")?;
let result = parent2.with_added(relative_path);
if !result.exists() {
return Err(format!("detected path does not exist: {}", result.display()).into());
}
Ok(result)
}
4 changes: 2 additions & 2 deletions cpp_to_rust/cpp_to_rust_common/src/serializable.in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub struct Target {
pub family: Family,
pub env: Env,
pub pointer_width: PointerWidth,
//pub vendor: Vendor,
// pub vendor: Vendor,
pub endian: Endian,
}
#[derive(Debug, Clone, PartialEq, Eq)]
Expand All @@ -73,7 +73,7 @@ pub enum Condition {
Family(Family),
Env(Env),
PointerWidth(PointerWidth),
//Vendor(Vendor),
// Vendor(Vendor),
Endian(Endian),
And(Vec<Condition>),
Or(Vec<Condition>),
Expand Down
28 changes: 14 additions & 14 deletions cpp_to_rust/cpp_to_rust_common/src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,24 +108,24 @@ pub fn current_pointer_width() -> PointerWidth {
PointerWidth::P64
}

//#[derive(Debug, Clone, Copy, PartialEq, Eq)]
//pub enum Vendor {
// #[derive(Debug, Clone, Copy, PartialEq, Eq)]
// pub enum Vendor {
// Apple,
// PC,
// Unknown,
//}
//#[cfg(target_vendor = "apple")]
//pub fn current_vendor() -> Vendor {
// }
// #[cfg(target_vendor = "apple")]
// pub fn current_vendor() -> Vendor {
// Vendor::Apple
//}
//#[cfg(target_vendor = "pc")]
//pub fn current_vendor() -> Vendor {
// }
// #[cfg(target_vendor = "pc")]
// pub fn current_vendor() -> Vendor {
// Vendor::PC
//}
//#[cfg(target_vendor = "unknown")]
//pub fn current_vendor() -> Vendor {
// }
// #[cfg(target_vendor = "unknown")]
// pub fn current_vendor() -> Vendor {
// Vendor::Unknown
//}
// }

#[cfg(target_endian = "little")]
pub fn current_endian() -> Endian {
Expand All @@ -144,7 +144,7 @@ pub fn current_target() -> Target {
family: current_family(),
env: current_env(),
pointer_width: current_pointer_width(),
//vendor: current_vendor(),
// vendor: current_vendor(),
endian: current_endian(),
}
}
Expand All @@ -159,7 +159,7 @@ impl Condition {
Family(ref family) => &target.family == family,
Env(ref env) => &target.env == env,
PointerWidth(ref pointer_width) => &target.pointer_width == pointer_width,
//Vendor(ref vendor) => &target.vendor == vendor,
// Vendor(ref vendor) => &target.vendor == vendor,
Endian(ref endian) => &target.endian == endian,
And(ref conditions) => conditions.iter().all(|c| c.eval(target)),
Or(ref conditions) => conditions.iter().any(|c| c.eval(target)),
Expand Down
10 changes: 7 additions & 3 deletions cpp_to_rust/cpp_to_rust_common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ pub fn is_msvc() -> bool {


#[cfg(windows)]
pub fn exe_suffix() -> &'static str { return ".exe"; }
pub fn exe_suffix() -> &'static str {
return ".exe";
}

#[cfg(not(windows))]
pub fn exe_suffix() -> &'static str { return ""; }
pub fn exe_suffix() -> &'static str {
return "";
}


pub fn add_to_multihash<K: Eq + Hash + Clone, T, V: Default + Extend<T>>(hash: &mut HashMap<K, V>,
Expand Down Expand Up @@ -57,7 +61,7 @@ pub fn run_command(command: &mut Command, fetch_stdout: bool, pipe_output: bool)
};

let status = command.status()
.chain_err(|| format!("command execution failed: {:?}", command))?;
.chain_err(|| format!("command execution failed: {:?}", command))?;
if status.success() {
Ok(if let Some(output) = output {
if fetch_stdout {
Expand Down
Loading

0 comments on commit 99df09e

Please sign in to comment.