|
1 | 1 | extern crate make_cmd;
|
2 | 2 |
|
3 | 3 | use std::env;
|
4 |
| -use std::path::Path; |
| 4 | +use std::path::{Path, PathBuf}; |
5 | 5 | use std::process::Command;
|
| 6 | +use std::fs::{self, File}; |
| 7 | +use std::io::Write; |
6 | 8 |
|
7 | 9 | fn main() {
|
| 10 | + println!("cargo:rerun-if-changed=libui"); |
8 | 11 | if !Path::new("libui/.git").exists() {
|
9 |
| - Command::new("git").args(&["submodule", "update", "--init"]).status().unwrap(); |
| 12 | + Command::new("git").args(&["submodule", "update", "--init"]).status().expect("Could not update libui submodule"); |
10 | 13 | }
|
11 |
| - |
| 14 | + |
| 15 | + let cwd = env::current_dir().unwrap(); |
| 16 | + |
| 17 | + let libui_path = cwd.join("libui"); |
| 18 | + env::set_current_dir(&libui_path).expect("Could not change dir"); |
| 19 | + |
| 20 | + // Run CMake |
| 21 | + //let cmake_cache_path = (&libui_path).join("CMakeCache.txt"); |
| 22 | + //if cmake_cache_path.exists() { |
| 23 | + // fs::remove_file(cmake_cache_path).expect("Could not remove cmake cache"); |
| 24 | + //} |
| 25 | + Command::new("cmake").arg(".").output().expect("cmake failed"); |
| 26 | + |
| 27 | + // Run Make |
| 28 | + let libui_out_path = (&libui_path).join("out"); |
| 29 | + if ! libui_out_path.exists() { |
| 30 | + println!("Creating out dir"); |
| 31 | + fs::create_dir(&libui_out_path).expect("Could not create out dir"); |
| 32 | + } |
| 33 | + make_cmd::gnu_make().status().expect("Make failed"); |
| 34 | + |
| 35 | + // Copy the output to the build folder |
12 | 36 | let out_dir = env::var("OUT_DIR").unwrap();
|
13 |
| - let outdir_argument = format!("OUTDIR={}", out_dir); |
14 |
| - let objdir_argument = format!("OBJDIR={}/obj", out_dir); |
15 |
| - make_cmd::gnu_make().args(&["-C", "libui", &*outdir_argument, &*objdir_argument]) |
16 |
| - .status() |
17 |
| - .unwrap(); |
| 37 | + let out_path = Path::new(&out_dir); |
| 38 | + for entry in fs::read_dir(&libui_out_path).unwrap() { |
| 39 | + let entry = entry.expect("IO error while reading"); |
| 40 | + let name = entry.file_name(); |
| 41 | + let target = out_path.join(name); |
| 42 | + fs::copy(&entry.path(), &target).expect("Could not copy file"); |
| 43 | + println!("Copying file from {} to {}", entry.path().display(), target.display()); |
| 44 | + } |
| 45 | + |
18 | 46 |
|
| 47 | + // Configure cargo |
19 | 48 | println!("cargo:rustc-link-lib=dylib=ui");
|
20 | 49 | println!("cargo:rustc-link-search={}", out_dir);
|
| 50 | + //panic!(); |
21 | 51 | }
|
22 | 52 |
|
0 commit comments