Skip to content

Commit

Permalink
Require ninja when building with MSVC.
Browse files Browse the repository at this point in the history
By default shaderc is built with msbuild when building with MSVC.
Unfortunately this often causes the build to fail due to excessively
long path names created by the msbuild project generator. This is
especially true when shaderc is built as a dependency of another
project, since in that case it will build in a nested subdirectory.

The best solution to this problem is to build with ninja instead, but
this solution is not obvious especially for users of downstream
projects, who are unlikely to have read the shaderc README.

To avoid this problem, we make ninja a hard requirement when building
with MSVC. This causes the build to fail with 'couldn't find required
command: "ninja"' when ninja is not available. This at least points the
user in the right direction.
  • Loading branch information
djcsdy authored and antiagainst committed Apr 12, 2019
1 parent aece59f commit 367a4dd
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions build/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn build_shaderc(shaderc_dir: &PathBuf, use_ninja: bool) -> PathBuf {
config.build()
}

fn build_shaderc_msvc(shaderc_dir: &PathBuf, use_ninja: bool) -> PathBuf {
fn build_shaderc_msvc(shaderc_dir: &PathBuf) -> PathBuf {
let mut config = cmake::Config::new(shaderc_dir);
config.profile("Release")
.define("CMAKE_POSITION_INDEPENDENT_CODE", "ON")
Expand All @@ -47,10 +47,8 @@ fn build_shaderc_msvc(shaderc_dir: &PathBuf, use_ninja: bool) -> PathBuf {
.define("CMAKE_CXX_FLAGS", " /nologo /EHsc")
.define("CMAKE_C_FLAGS_RELEASE", " /nologo /EHsc")
.define("CMAKE_CXX_FLAGS_RELEASE", " /nologo /EHsc")
.define("CMAKE_INSTALL_LIBDIR", "lib");
if use_ninja {
config.generator("Ninja");
}
.define("CMAKE_INSTALL_LIBDIR", "lib")
.generator("Ninja");
config.build()
}

Expand All @@ -70,17 +68,17 @@ fn main() {
finder.must_have("git");
finder.must_have("python");

let has_ninja = finder.maybe_have("ninja").is_some();

let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap();

let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let shaderc_dir = Path::new(&manifest_dir).join("build");

let mut lib_path = if target_env == "msvc" {
build_shaderc_msvc(&shaderc_dir, has_ninja)
finder.must_have("ninja");
build_shaderc_msvc(&shaderc_dir)
} else {
let has_ninja = finder.maybe_have("ninja").is_some();
build_shaderc(&shaderc_dir, has_ninja)
};

Expand Down

0 comments on commit 367a4dd

Please sign in to comment.