build system: consolidate duplicate code and more

* add ability to add assembly files when building an exe, obj, or lib
 * add implicit cast from `[N]T` to `?[]const T` (closes #343)
 * remove link_exe and link_lib in favor of allowing build_exe and
   build_lib support no root zig source file
This commit is contained in:
Andrew Kelley
2017-04-26 19:17:05 -04:00
parent 09bc4d6ba3
commit 7b0542d08b
13 changed files with 323 additions and 694 deletions

View File

@@ -33,9 +33,11 @@ static const char *get_libc_static_file(CodeGen *g, const char *file) {
static Buf *build_o(CodeGen *parent_gen, const char *oname) {
Buf *source_basename = buf_sprintf("%s.zig", oname);
Buf *full_path = buf_alloc();
os_path_join(parent_gen->zig_std_special_dir, source_basename, full_path);
ZigTarget *child_target = parent_gen->is_native_target ? nullptr : &parent_gen->zig_target;
CodeGen *child_gen = codegen_create(parent_gen->zig_std_special_dir, child_target);
CodeGen *child_gen = codegen_create(full_path, child_target);
child_gen->link_libc = parent_gen->link_libc;
child_gen->link_libs.resize(parent_gen->link_libs.length);
@@ -60,15 +62,7 @@ static Buf *build_o(CodeGen *parent_gen, const char *oname) {
codegen_set_mmacosx_version_min(child_gen, parent_gen->mmacosx_version_min);
codegen_set_mios_version_min(child_gen, parent_gen->mios_version_min);
Buf *full_path = buf_alloc();
os_path_join(parent_gen->zig_std_special_dir, source_basename, full_path);
Buf source_code = BUF_INIT;
if (os_fetch_file_path(full_path, &source_code)) {
zig_panic("unable to fetch file: %s\n", buf_ptr(full_path));
}
codegen_add_root_code(child_gen, parent_gen->zig_std_special_dir, source_basename, &source_code);
codegen_build(child_gen);
const char *o_ext = target_o_file_ext(&child_gen->zig_target);
Buf *o_out = buf_sprintf("%s%s", oname, o_ext);
codegen_link(child_gen, buf_ptr(o_out));