Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve build time on Windows with clang-cl #80

Merged
merged 4 commits into from
Aug 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,22 @@ fn build_windows_dll(data: &build_data::Data, dll_name: &str, def_file: &str) {
build.include(fixup_path(file));
}

// compile source files to object files (workaround for clang-cl not supporting /MP)
for file in data.sources {
build.file(fixup_path(file));
}
let obj_paths = build.compile_intermediates();

let build = cc::Build::new();
let mut cmd = build.get_compiler().to_command();
let out_string = env::var("OUT_DIR").unwrap();
let out_path = Path::new(&out_string);

// link with object files compiled previously
for obj_path in &obj_paths {
cmd.arg(obj_path);
}

for lib in data.use_libs {
cmd.arg(out_path.join(format!("{}.lib", lib.to_data().lib)));
}
Expand All @@ -123,13 +135,6 @@ fn build_windows_dll(data: &build_data::Data, dll_name: &str, def_file: &str) {
if dll_name == "libGLESv2" {
// transitive lib (that's the only case)
cmd.arg(out_path.join("preprocessor.lib"));
for file in data.sources {
cmd.arg(fixup_path(file));
}
} else {
for file in data.sources {
cmd.arg(fixup_path(file));
}
}

// Enable multiprocessing for faster builds.
Expand Down Expand Up @@ -229,7 +234,8 @@ fn build_lib(compiled_libraries: &mut HashSet<Libs>, target: &String, lib: Libs)
build
.flag_if_supported("/wd4100")
.flag_if_supported("/wd4127")
.flag_if_supported("/wd9002");
.flag_if_supported("/wd9002")
.flag_if_supported("-Wno-unused-command-line-argument");

if target.contains("x86_64") || target.contains("i686") {
build
Expand Down Expand Up @@ -389,11 +395,12 @@ fn fixup_path(path: &str) -> String {
fn generate_gl_bindings() {
println!("generate_gl_bindings");
use gl_generator::{Api, Fallbacks, Profile, Registry};
use std::fs::File;
use std::{fs::File, io::Write};

let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());

let mut file = File::create(&out_dir.join("egl_bindings.rs")).unwrap();
file.write_all(b"#[allow(unused_imports)]\n").unwrap();
Registry::new(
Api::Egl,
(1, 5),
Expand All @@ -412,6 +419,7 @@ fn generate_gl_bindings() {
.unwrap();

let mut file = File::create(&out_dir.join("gles_bindings.rs")).unwrap();
file.write_all(b"#[allow(unused_imports)]\n").unwrap();
Registry::new(Api::Gles2, (2, 0), Profile::Core, Fallbacks::None, [])
.write_bindings(gl_generator::StaticGenerator, &mut file)
.unwrap();
Expand Down