From 18ffb9136d9337cf1e92dda419ea868fb90d7757 Mon Sep 17 00:00:00 2001 From: Xavier Bouchoux Date: Sat, 25 Nov 2023 17:17:58 +0100 Subject: [PATCH] enable use_llvm if clang c_frontend is required --- src/Compilation.zig | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Compilation.zig b/src/Compilation.zig index 598f7a5a8b19..3812fc1d87cf 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -1088,6 +1088,17 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { const comp = try arena.create(Compilation); const root_name = try arena.dupeZ(u8, options.root_name); + // Make a decision on whether to use Clang or Aro for translate-c and compiling C files. + const c_frontend: CFrontend = blk: { + if (options.use_clang) |want_clang| { + break :blk if (want_clang) .clang else .aro; + } + break :blk if (build_options.have_llvm) .clang else .aro; + }; + if (!build_options.have_llvm and c_frontend == .clang) { + return error.ZigCompilerNotBuiltWithLLVMExtensions; + } + // Make a decision on whether to use LLVM or our own backend. const use_lib_llvm = options.use_lib_llvm orelse build_options.have_llvm; const use_llvm = blk: { @@ -1098,6 +1109,10 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { if (options.emit_llvm_ir != null or options.emit_llvm_bc != null) break :blk true; + // If clang is requested for compilation of c/c++ files. + if (options.c_source_files.len != 0 and c_frontend == .clang) + break :blk true; + // If we have no zig code to compile, no need for LLVM. if (options.main_mod == null) break :blk false; @@ -1325,17 +1340,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { break :pic explicit; } else pie or must_pic; - // Make a decision on whether to use Clang or Aro for translate-c and compiling C files. - const c_frontend: CFrontend = blk: { - if (options.use_clang) |want_clang| { - break :blk if (want_clang) .clang else .aro; - } - break :blk if (build_options.have_llvm) .clang else .aro; - }; - if (!build_options.have_llvm and c_frontend == .clang) { - return error.ZigCompilerNotBuiltWithLLVMExtensions; - } - const is_safe_mode = switch (options.optimize_mode) { .Debug, .ReleaseSafe => true, .ReleaseFast, .ReleaseSmall => false,