Skip to content

stage1: implement --full-name #6317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/all_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2302,6 +2302,7 @@ struct CodeGen {
bool test_is_evented;
bool linker_z_nodelete;
bool linker_z_defs;
bool is_full_out_name; // if full a prefix/extension should not be added

Buf *root_out_name;
Buf *test_filter;
Expand Down
59 changes: 33 additions & 26 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ void codegen_set_strip(CodeGen *g, bool strip) {
}
}

void codegen_set_out_name(CodeGen *g, Buf *out_name) {
void codegen_set_out_name(CodeGen *g, Buf *out_name, bool full) {
g->root_out_name = out_name;
g->is_full_out_name = full;
}

void codegen_add_lib_dir(CodeGen *g, const char *dir) {
Expand Down Expand Up @@ -10772,6 +10773,7 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
}
cache_buf(ch, compiler_id);
cache_buf(ch, g->root_out_name);
cache_bool(ch, g->is_full_out_name);
cache_buf(ch, g->zig_lib_dir);
cache_buf(ch, g->zig_std_dir);
cache_list_of_link_lib(ch, g->link_libs_list.items, g->link_libs_list.length);
Expand Down Expand Up @@ -10871,32 +10873,37 @@ static void resolve_out_paths(CodeGen *g) {
if (g->emit_bin) {
Buf *out_basename = buf_create_from_buf(g->root_out_name);
Buf *o_basename = buf_create_from_buf(g->root_out_name);
switch (g->out_type) {
case OutTypeUnknown:
zig_unreachable();
case OutTypeObj:
if (need_llvm_module(g) && g->link_objects.length != 0 && !g->enable_cache &&
buf_eql_buf(o_basename, out_basename))
{
// make it not collide with main output object
buf_append_str(o_basename, ".root");
}
buf_append_str(o_basename, target_o_file_ext(g->zig_target));
buf_append_str(out_basename, target_o_file_ext(g->zig_target));
break;
case OutTypeExe:
buf_append_str(o_basename, target_o_file_ext(g->zig_target));
buf_append_str(out_basename, target_exe_file_ext(g->zig_target));
break;
case OutTypeLib:
buf_append_str(o_basename, target_o_file_ext(g->zig_target));
buf_resize(out_basename, 0);
buf_append_str(out_basename, target_lib_file_prefix(g->zig_target));
buf_append_buf(out_basename, g->root_out_name);
buf_append_str(out_basename, target_lib_file_ext(g->zig_target, !g->is_dynamic,
g->version_major, g->version_minor, g->version_patch));
break;

if (!g->is_full_out_name) {
switch (g->out_type) {
case OutTypeUnknown:
zig_unreachable();
case OutTypeObj:
buf_append_str(out_basename, target_o_file_ext(g->zig_target));
break;
case OutTypeExe:
buf_append_str(out_basename, target_exe_file_ext(g->zig_target));
break;
case OutTypeLib:
buf_resize(out_basename, 0);
buf_append_str(out_basename, target_lib_file_prefix(g->zig_target));
buf_append_buf(out_basename, g->root_out_name);
buf_append_str(out_basename, target_lib_file_ext(g->zig_target, !g->is_dynamic,
g->version_major, g->version_minor, g->version_patch));
break;
}
}

buf_append_str(o_basename, target_o_file_ext(g->zig_target));
if (need_llvm_module(g) && g->link_objects.length != 0 && !g->enable_cache &&
buf_eql_buf(o_basename, out_basename))
{
// make it not collide with main output object
buf_resize(o_basename, 0);
buf_append_str(o_basename, ".root");
buf_append_str(o_basename, target_o_file_ext(g->zig_target));
}

os_path_join(g->output_dir, o_basename, &g->o_file_output_path);
os_path_join(g->output_dir, out_basename, &g->bin_file_output_path);
}
Expand Down
2 changes: 1 addition & 1 deletion src/codegen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void codegen_set_each_lib_rpath(CodeGen *codegen, bool each_lib_rpath);

void codegen_set_strip(CodeGen *codegen, bool strip);
void codegen_set_errmsg_color(CodeGen *codegen, ErrColor err_color);
void codegen_set_out_name(CodeGen *codegen, Buf *out_name);
void codegen_set_out_name(CodeGen *codegen, Buf *out_name, bool full);
void codegen_add_lib_dir(CodeGen *codegen, const char *dir);
void codegen_add_forbidden_lib(CodeGen *codegen, Buf *lib);
LinkLib *codegen_add_link_lib(CodeGen *codegen, Buf *lib);
Expand Down
9 changes: 7 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) {
" -fno-emit-h (default) do not generate a C header file (.h)\n"
" --libc [file] Provide a file which specifies libc paths\n"
" --name [name] override output name\n"
" --full-name [name] override full output name and extension\n"
" --output-dir [dir] override output directory (defaults to cwd)\n"
" --pkg-begin [name] [path] make pkg available to import and push current pkg\n"
" --pkg-end pop current pkg\n"
Expand Down Expand Up @@ -384,6 +385,7 @@ static int main0(int argc, char **argv) {
bool is_dynamic = false;
OutType out_type = OutTypeUnknown;
const char *out_name = nullptr;
bool is_full_out_name = false;
bool verbose_tokenize = false;
bool verbose_ast = false;
bool verbose_link = false;
Expand Down Expand Up @@ -553,7 +555,7 @@ static int main0(int argc, char **argv) {
BuildModeDebug, override_lib_dir, nullptr, &full_cache_dir, false, root_progress_node);
g->valgrind_support = valgrind_support;
g->enable_time_report = timing_info;
codegen_set_out_name(g, buf_create_from_str("build"));
codegen_set_out_name(g, buf_create_from_str("build"), false);

args.items[2] = buf_ptr(&build_file_dirname);
args.items[3] = buf_ptr(&full_cache_dir);
Expand Down Expand Up @@ -1134,6 +1136,9 @@ static int main0(int argc, char **argv) {
}
} else if (strcmp(arg, "--name") == 0) {
out_name = argv[i];
} else if (strcmp(arg, "--full-name") == 0) {
is_full_out_name = true;
out_name = argv[i];
} else if (strcmp(arg, "--dynamic-linker") == 0) {
dynamic_linker = argv[i];
} else if (strcmp(arg, "--libc") == 0) {
Expand Down Expand Up @@ -1589,7 +1594,7 @@ static int main0(int argc, char **argv) {
g->emit_asm = emit_asm;
g->emit_llvm_ir = emit_llvm_ir;

codegen_set_out_name(g, buf_out_name);
codegen_set_out_name(g, buf_out_name, is_full_out_name);
codegen_set_lib_version(g, ver_major, ver_minor, ver_patch);
g->want_single_threaded = want_single_threaded;
codegen_set_linker_script(g, linker_script);
Expand Down