Bug 1632444 - Correctly detect target OS when deciding what shaders to optimize. r=jrmuizel

A previous patch attempted to optimize only GL or GLES shaders,
depending on the target platform. However, it was trying to detect the
platform by using `cfg!(target_os = {})`, but as this is in a
build script that actually detects the host platform instead. This
resulted in the wrong version of shaders being optimized, and
therefore falling back to unoptimized shaders at runtime.

This fix uses `env::var("CARGO_CFG_TARGET_OS")` instead, which works
correctly in build scripts.

Differential Revision: https://phabricator.services.mozilla.com/D72127
This commit is contained in:
Jamie Nicol 2020-04-23 12:23:35 +00:00
Родитель b59fd6199b
Коммит f9253cf629
1 изменённых файлов: 3 добавлений и 4 удалений

Просмотреть файл

@ -104,10 +104,9 @@ fn write_optimized_shaders(shader_dir: &Path, shader_file: &mut File, out_dir: &
// The full set of optimized shaders can be quite large, so only optimize
// for the GL version we expect to be used on the target platform. If a different GL
// version is used we will simply fall back to the unoptimized shaders.
let shader_versions = if cfg!(target_os = "android") || cfg!(target_os = "windows") {
[ShaderVersion::Gles]
} else {
[ShaderVersion::Gl]
let shader_versions = match env::var("CARGO_CFG_TARGET_OS").as_ref().map(|s| &**s) {
Ok("android") | Ok("windows") => [ShaderVersion::Gles],
_ => [ShaderVersion::Gl],
};
let mut shaders = Vec::default();