Skip to content
Closed
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: 15 additions & 11 deletions src/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand Down