From d3ff011da35c1b26d318445bebb200c0e204cdcf Mon Sep 17 00:00:00 2001 From: Bo Date: Fri, 16 Aug 2024 17:20:29 +0800 Subject: [PATCH] Fix detect family: should detect emscripten as clang, closes #1185 (#1186) --- src/detect_compiler_family.c | 5 +++++ src/tool.rs | 15 ++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/detect_compiler_family.c b/src/detect_compiler_family.c index e66dcc044..2d49b1a13 100644 --- a/src/detect_compiler_family.c +++ b/src/detect_compiler_family.c @@ -5,3 +5,8 @@ #ifdef __GNUC__ #pragma message "gcc" #endif + +#ifdef __EMSCRIPTEN__ +#pragma message "emscripten" +#endif + diff --git a/src/tool.rs b/src/tool.rs index 3a015f369..c6d8f152f 100644 --- a/src/tool.rs +++ b/src/tool.rs @@ -169,18 +169,19 @@ impl Tool { let clang = stdout.contains(r#""clang""#); let gcc = stdout.contains(r#""gcc""#); + let emscripten = stdout.contains(r#""emscripten""#); - match (clang, accepts_cl_style_flags, gcc) { - (clang_cl, true, _) => Ok(ToolFamily::Msvc { clang_cl }), - (true, false, _) => Ok(ToolFamily::Clang { + match (clang, accepts_cl_style_flags, gcc, emscripten) { + (clang_cl, true, _, false) => Ok(ToolFamily::Msvc { clang_cl }), + (true, _, _, _) | (_, _, _, true) => Ok(ToolFamily::Clang { zig_cc: is_zig_cc(path, cargo_output), }), - (false, false, true) => Ok(ToolFamily::Gnu), - (false, false, false) => { - cargo_output.print_warning(&"Compiler family detection failed since it does not define `__clang__`, `__GNUC__` or `_MSC_VER`, fallback to treating it as GNU"); + (false, false, true, _) => Ok(ToolFamily::Gnu), + (false, false, false, false) => { + cargo_output.print_warning(&"Compiler family detection failed since it does not define `__clang__`, `__GNUC__` or `__EMSCRIPTEN__`, also does not accept cl style flag `-?`, fallback to treating it as GNU"); Err(Error::new( ErrorKind::ToolFamilyMacroNotFound, - "Expects macro `__clang__`, `__GNUC__` or `_MSC_VER`, but found none", + "Expects macro `__clang__`, `__GNUC__` or `__EMSCRIPTEN__`, or accepts cl style flag `-?`, but found none", )) } }