build: fix libc path finding

This commit is contained in:
Andrew Kelley 2016-02-02 15:04:14 -07:00
parent 5824b15249
commit 7af59c76e4
8 changed files with 54 additions and 48 deletions

View file

@ -70,13 +70,13 @@ compromises backward compatibility.
### Debug / Development Build ### Debug / Development Build
If you have gcc or clang installed, you can find out what `ZIG_LIBC_DIR` should If you have gcc or clang installed, you can find out what `ZIG_LIBC_LIB_DIR` should
be set to (example below). be set to (example below). `ZIG_LIBC_INCLUDE_DIR` likely can be set to `/usr/include`.
``` ```
mkdir build mkdir build
cd build cd build
cmake .. -DCMAKE_INSTALL_PREFIX=$(pwd) -DZIG_LIBC_DIR=$(dirname $(dirname $(cc -print-file-name=crt1.o))) cmake .. -DCMAKE_INSTALL_PREFIX=$(pwd) -DZIG_LIBC_LIB_DIR=$(dirname $(cc -print-file-name=crt1.o)) -DZIG_LIBC_INCLUDE_DIR=/usr/include
make make
make install make install
./run_tests ./run_tests
@ -84,13 +84,13 @@ make install
### Release / Install Build ### Release / Install Build
Once installed, `ZIG_LIBC_DIR` can be overridden by the `--libc-path` parameter Once installed, `ZIG_LIBC_LIB_DIR` and `ZIG_LIBC_INCLUDE_DIR` can be overridden
to the zig binary. by the `--libc-lib-dir` and `--libc-include-dir` parameters to the zig binary.
``` ```
mkdir build mkdir build
cd build cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DZIG_LIBC_DIR=path/to/libc/dir cmake .. -DCMAKE_BUILD_TYPE=Release -DZIG_LIBC_LIB_DIR=/some/path -DZIG_LIBC_INCLUDE_DIR=/some/path
make make
sudo make install sudo make install
``` ```

View file

@ -1062,9 +1062,8 @@ struct CodeGen {
bool strip_debug_symbols; bool strip_debug_symbols;
bool have_exported_main; bool have_exported_main;
bool link_libc; bool link_libc;
Buf *libc_path; Buf *libc_lib_dir;
Buf *libc_lib_path; Buf *libc_include_dir;
Buf *libc_include_path;
CodeGenBuildType build_type; CodeGenBuildType build_type;
LLVMTargetMachineRef target_machine; LLVMTargetMachineRef target_machine;
LLVMZigDIFile *dummy_di_file; LLVMZigDIFile *dummy_di_file;

View file

@ -5486,20 +5486,12 @@ bool handle_is_ptr(TypeTableEntry *type_entry) {
} }
void find_libc_path(CodeGen *g) { void find_libc_path(CodeGen *g) {
if (!g->libc_path || buf_len(g->libc_path) == 0) { // later we can handle this better by reporting an error via the normal mechanism
g->libc_path = buf_create_from_str(ZIG_LIBC_DIR); if (!g->libc_lib_dir || buf_len(g->libc_lib_dir) == 0) {
if (!g->libc_path || buf_len(g->libc_path) == 0) { zig_panic("Unable to determine libc lib path. probably need to reconfigure");
// later we can handle this better by reporting an error via the normal mechanism
zig_panic("Unable to determine libc path. You can use `--libc-path`");
}
} }
if (!g->libc_lib_path) { if (!g->libc_include_dir || buf_len(g->libc_include_dir) == 0) {
g->libc_lib_path = buf_alloc(); zig_panic("Unable to determine libc include path. probably need to reconfigure");
os_path_join(g->libc_path, buf_create_from_str("lib"), g->libc_lib_path);
}
if (!g->libc_include_path) {
g->libc_include_path = buf_alloc();
os_path_join(g->libc_path, buf_create_from_str("include"), g->libc_include_path);
} }
} }

View file

@ -33,6 +33,9 @@ CodeGen *codegen_create(Buf *root_source_dir) {
g->next_error_index = 1; g->next_error_index = 1;
g->error_value_count = 1; g->error_value_count = 1;
g->libc_lib_dir = buf_create_from_str(ZIG_LIBC_LIB_DIR);
g->libc_include_dir = buf_create_from_str(ZIG_LIBC_INCLUDE_DIR);
return g; return g;
} }
@ -69,8 +72,12 @@ void codegen_set_out_name(CodeGen *g, Buf *out_name) {
g->root_out_name = out_name; g->root_out_name = out_name;
} }
void codegen_set_libc_path(CodeGen *g, Buf *libc_path) { void codegen_set_libc_lib_dir(CodeGen *g, Buf *libc_lib_dir) {
g->libc_path = libc_path; g->libc_lib_dir = libc_lib_dir;
}
void codegen_set_libc_include_dir(CodeGen *g, Buf *libc_include_dir) {
g->libc_include_dir = libc_include_dir;
} }
void codegen_add_lib_dir(CodeGen *g, const char *dir) { void codegen_add_lib_dir(CodeGen *g, const char *dir) {
@ -3710,7 +3717,7 @@ static void generate_h_file(CodeGen *g) {
static const char *get_libc_file(CodeGen *g, const char *file) { static const char *get_libc_file(CodeGen *g, const char *file) {
Buf *out_buf = buf_alloc(); Buf *out_buf = buf_alloc();
os_path_join(g->libc_lib_path, buf_create_from_str(file), out_buf); os_path_join(g->libc_lib_dir, buf_create_from_str(file), out_buf);
return buf_ptr(out_buf); return buf_ptr(out_buf);
} }

View file

@ -23,7 +23,8 @@ void codegen_set_verbose(CodeGen *codegen, bool verbose);
void codegen_set_errmsg_color(CodeGen *codegen, ErrColor err_color); void codegen_set_errmsg_color(CodeGen *codegen, ErrColor err_color);
void codegen_set_out_type(CodeGen *codegen, OutType out_type); void codegen_set_out_type(CodeGen *codegen, OutType out_type);
void codegen_set_out_name(CodeGen *codegen, Buf *out_name); void codegen_set_out_name(CodeGen *codegen, Buf *out_name);
void codegen_set_libc_path(CodeGen *codegen, Buf *libc_path); void codegen_set_libc_lib_dir(CodeGen *codegen, Buf *libc_lib_dir);
void codegen_set_libc_include_dir(CodeGen *codegen, Buf *libc_include_dir);
void codegen_add_lib_dir(CodeGen *codegen, const char *dir); void codegen_add_lib_dir(CodeGen *codegen, const char *dir);
void codegen_add_root_code(CodeGen *g, Buf *source_dir, Buf *source_basename, Buf *source_code); void codegen_add_root_code(CodeGen *g, Buf *source_dir, Buf *source_basename, Buf *source_code);

View file

@ -8,7 +8,8 @@
#define ZIG_HEADERS_DIR "@CMAKE_INSTALL_PREFIX@/@C_HEADERS_DEST@" #define ZIG_HEADERS_DIR "@CMAKE_INSTALL_PREFIX@/@C_HEADERS_DEST@"
#define ZIG_STD_DIR "@CMAKE_INSTALL_PREFIX@/@ZIG_STD_DEST@" #define ZIG_STD_DIR "@CMAKE_INSTALL_PREFIX@/@ZIG_STD_DEST@"
#define ZIG_LIBC_DIR "@ZIG_LIBC_DIR@" #define ZIG_LIBC_INCLUDE_DIR "@ZIG_LIBC_INCLUDE_DIR@"
#define ZIG_LIBC_LIB_DIR "@ZIG_LIBC_LIB_DIR@"
#cmakedefine ZIG_LLVM_OLD_CXX_ABI #cmakedefine ZIG_LLVM_OLD_CXX_ABI

View file

@ -16,22 +16,23 @@
static int usage(const char *arg0) { static int usage(const char *arg0) {
fprintf(stderr, "Usage: %s [command] [options]\n" fprintf(stderr, "Usage: %s [command] [options]\n"
"Commands:\n" "Commands:\n"
" build create executable, object, or library from target\n" " build create executable, object, or library from target\n"
" version print version number and exit\n" " version print version number and exit\n"
" parseh convert a c header file to zig extern declarations\n" " parseh convert a c header file to zig extern declarations\n"
"Options:\n" "Options:\n"
" --release build with optimizations on and debug protection off\n" " --release build with optimizations on and debug protection off\n"
" --static output will be statically linked\n" " --static output will be statically linked\n"
" --strip exclude debug symbols\n" " --strip exclude debug symbols\n"
" --export [exe|lib|obj] override output type\n" " --export [exe|lib|obj] override output type\n"
" --name [name] override output name\n" " --name [name] override output name\n"
" --output [file] override destination path\n" " --output [file] override destination path\n"
" --verbose turn on compiler debug output\n" " --verbose turn on compiler debug output\n"
" --color [auto|off|on] enable or disable colored error messages\n" " --color [auto|off|on] enable or disable colored error messages\n"
" --libc-path [path] set the C compiler data path\n" " --libc-lib-dir [path] set the C compiler data path\n"
" -isystem [dir] add additional search path for other .h files\n" " --libc-include-dir [path] set the C compiler data path\n"
" -dirafter [dir] same as -isystem but do it last\n" " -isystem [dir] add additional search path for other .h files\n"
" --library-path [dir] add a directory to the library search path\n" " -dirafter [dir] same as -isystem but do it last\n"
" --library-path [dir] add a directory to the library search path\n"
, arg0); , arg0);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -55,7 +56,8 @@ int main(int argc, char **argv) {
const char *out_name = nullptr; const char *out_name = nullptr;
bool verbose = false; bool verbose = false;
ErrColor color = ErrColorAuto; ErrColor color = ErrColorAuto;
const char *libc_path = nullptr; const char *libc_lib_dir = nullptr;
const char *libc_include_dir = nullptr;
ZigList<const char *> clang_argv = {0}; ZigList<const char *> clang_argv = {0};
ZigList<const char *> lib_dirs = {0}; ZigList<const char *> lib_dirs = {0};
int err; int err;
@ -102,8 +104,10 @@ int main(int argc, char **argv) {
} }
} else if (strcmp(arg, "--name") == 0) { } else if (strcmp(arg, "--name") == 0) {
out_name = argv[i]; out_name = argv[i];
} else if (strcmp(arg, "--libc-path") == 0) { } else if (strcmp(arg, "--libc-lib-dir") == 0) {
libc_path = argv[i]; libc_lib_dir = argv[i];
} else if (strcmp(arg, "--libc-include-dir") == 0) {
libc_include_dir = argv[i];
} else if (strcmp(arg, "-isystem") == 0) { } else if (strcmp(arg, "-isystem") == 0) {
clang_argv.append("-isystem"); clang_argv.append("-isystem");
clang_argv.append(argv[i]); clang_argv.append(argv[i]);
@ -182,8 +186,10 @@ int main(int argc, char **argv) {
codegen_set_out_type(g, out_type); codegen_set_out_type(g, out_type);
if (out_name) if (out_name)
codegen_set_out_name(g, buf_create_from_str(out_name)); codegen_set_out_name(g, buf_create_from_str(out_name));
if (libc_path) if (libc_lib_dir)
codegen_set_libc_path(g, buf_create_from_str(libc_path)); codegen_set_libc_lib_dir(g, buf_create_from_str(libc_lib_dir));
if (libc_include_dir)
codegen_set_libc_include_dir(g, buf_create_from_str(libc_include_dir));
codegen_set_verbose(g, verbose); codegen_set_verbose(g, verbose);
codegen_set_errmsg_color(g, color); codegen_set_errmsg_color(g, color);

View file

@ -1413,7 +1413,7 @@ int parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const ch
clang_argv.append(ZIG_HEADERS_DIR); clang_argv.append(ZIG_HEADERS_DIR);
clang_argv.append("-isystem"); clang_argv.append("-isystem");
clang_argv.append(buf_ptr(codegen->libc_include_path)); clang_argv.append(buf_ptr(codegen->libc_include_dir));
for (int i = 0; i < codegen->clang_argv_len; i += 1) { for (int i = 0; i < codegen->clang_argv_len; i += 1) {
clang_argv.append(codegen->clang_argv[i]); clang_argv.append(codegen->clang_argv[i]);