Skip to content

Commit

Permalink
improve behavior of zig build (#754)
Browse files Browse the repository at this point in the history
See #748
  • Loading branch information
jfo authored and andrewrk committed Feb 7, 2018
1 parent 79ad1d9 commit c88e6e8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/main.cpp
Expand Up @@ -339,6 +339,7 @@ int main(int argc, char **argv) {
const char *zig_exe_path = arg0;
const char *build_file = "build.zig";
bool asked_for_help = false;
bool asked_to_init = false;

init_all_targets();

Expand All @@ -350,6 +351,9 @@ int main(int argc, char **argv) {
if (strcmp(argv[i], "--help") == 0) {
asked_for_help = true;
args.append(argv[i]);
} else if (strcmp(argv[i], "--init") == 0) {
asked_to_init = true;
args.append(argv[i]);
} else if (i + 1 < argc && strcmp(argv[i], "--build-file") == 0) {
build_file = argv[i + 1];
i += 1;
Expand Down Expand Up @@ -414,6 +418,7 @@ int main(int argc, char **argv) {
"\n"
"General Options:\n"
" --help Print this help and exit\n"
" --init Generate a build.zig template\n"
" --build-file [file] Override path to build.zig\n"
" --cache-dir [path] Override path to cache directory\n"
" --verbose Print commands before executing them\n"
Expand All @@ -426,7 +431,6 @@ int main(int argc, char **argv) {
" --prefix [path] Override default install prefix\n"
"\n"
"Project-specific options become available when the build file is found.\n"
"Run this command with no options to generate a build.zig template.\n"
"\n"
"Advanced Options:\n"
" --build-file [file] Override path to build.zig\n"
Expand All @@ -439,17 +443,26 @@ int main(int argc, char **argv) {
" --verbose-cimport Enable compiler debug output for C imports\n"
"\n"
, zig_exe_path);
return 0;
}
Buf *build_template_path = buf_alloc();
os_path_join(special_dir, buf_create_from_str("build_file_template.zig"), build_template_path);
return EXIT_SUCCESS;
} else if (asked_to_init) {
Buf *build_template_path = buf_alloc();
os_path_join(special_dir, buf_create_from_str("build_file_template.zig"), build_template_path);

if ((err = os_copy_file(build_template_path, &build_file_abs))) {
fprintf(stderr, "Unable to write build.zig template: %s\n", err_str(err));
} else {
fprintf(stderr, "Wrote build.zig template\n");
if ((err = os_copy_file(build_template_path, &build_file_abs))) {
fprintf(stderr, "Unable to write build.zig template: %s\n", err_str(err));
} else {
fprintf(stderr, "Wrote build.zig template\n");
}
return EXIT_SUCCESS;
}
return 1;

fprintf(stderr,
"No 'build.zig' file found.\n"
"Initialize a 'build.zig' template file with `zig build --init`,\n"
"or build an executable directly with `zig build-exe $FILENAME.zig`.\n"
"See: `zig build --help` or `zig help` for more options.\n"
);
return EXIT_FAILURE;
}

PackageTableEntry *build_pkg = codegen_create_package(g, buf_ptr(&build_file_dirname),
Expand Down
1 change: 1 addition & 0 deletions std/special/build_runner.zig
Expand Up @@ -149,6 +149,7 @@ fn usage(builder: &Builder, already_ran_build: bool, out_stream: &io.OutStream)
\\
\\General Options:
\\ --help Print this help and exit
\\ --init Generate a build.zig template
\\ --verbose Print commands before executing them
\\ --prefix [path] Override default install prefix
\\ --search-prefix [path] Add a path to look for binaries, libraries, headers
Expand Down

0 comments on commit c88e6e8

Please sign in to comment.