mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
build: fix libc path finding
This commit is contained in:
parent
5824b15249
commit
7af59c76e4
8 changed files with 54 additions and 48 deletions
12
README.md
12
README.md
|
|
@ -70,13 +70,13 @@ compromises backward compatibility.
|
|||
|
||||
### Debug / Development Build
|
||||
|
||||
If you have gcc or clang installed, you can find out what `ZIG_LIBC_DIR` should
|
||||
be set to (example below).
|
||||
If you have gcc or clang installed, you can find out what `ZIG_LIBC_LIB_DIR` should
|
||||
be set to (example below). `ZIG_LIBC_INCLUDE_DIR` likely can be set to `/usr/include`.
|
||||
|
||||
```
|
||||
mkdir 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 install
|
||||
./run_tests
|
||||
|
|
@ -84,13 +84,13 @@ make install
|
|||
|
||||
### Release / Install Build
|
||||
|
||||
Once installed, `ZIG_LIBC_DIR` can be overridden by the `--libc-path` parameter
|
||||
to the zig binary.
|
||||
Once installed, `ZIG_LIBC_LIB_DIR` and `ZIG_LIBC_INCLUDE_DIR` can be overridden
|
||||
by the `--libc-lib-dir` and `--libc-include-dir` parameters to the zig binary.
|
||||
|
||||
```
|
||||
mkdir 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
|
||||
sudo make install
|
||||
```
|
||||
|
|
|
|||
|
|
@ -1062,9 +1062,8 @@ struct CodeGen {
|
|||
bool strip_debug_symbols;
|
||||
bool have_exported_main;
|
||||
bool link_libc;
|
||||
Buf *libc_path;
|
||||
Buf *libc_lib_path;
|
||||
Buf *libc_include_path;
|
||||
Buf *libc_lib_dir;
|
||||
Buf *libc_include_dir;
|
||||
CodeGenBuildType build_type;
|
||||
LLVMTargetMachineRef target_machine;
|
||||
LLVMZigDIFile *dummy_di_file;
|
||||
|
|
|
|||
|
|
@ -5486,20 +5486,12 @@ bool handle_is_ptr(TypeTableEntry *type_entry) {
|
|||
}
|
||||
|
||||
void find_libc_path(CodeGen *g) {
|
||||
if (!g->libc_path || buf_len(g->libc_path) == 0) {
|
||||
g->libc_path = buf_create_from_str(ZIG_LIBC_DIR);
|
||||
if (!g->libc_path || buf_len(g->libc_path) == 0) {
|
||||
// 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_dir || buf_len(g->libc_lib_dir) == 0) {
|
||||
zig_panic("Unable to determine libc lib path. probably need to reconfigure");
|
||||
}
|
||||
}
|
||||
if (!g->libc_lib_path) {
|
||||
g->libc_lib_path = buf_alloc();
|
||||
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);
|
||||
if (!g->libc_include_dir || buf_len(g->libc_include_dir) == 0) {
|
||||
zig_panic("Unable to determine libc include path. probably need to reconfigure");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,9 @@ CodeGen *codegen_create(Buf *root_source_dir) {
|
|||
g->next_error_index = 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;
|
||||
}
|
||||
|
||||
|
|
@ -69,8 +72,12 @@ void codegen_set_out_name(CodeGen *g, Buf *out_name) {
|
|||
g->root_out_name = out_name;
|
||||
}
|
||||
|
||||
void codegen_set_libc_path(CodeGen *g, Buf *libc_path) {
|
||||
g->libc_path = libc_path;
|
||||
void codegen_set_libc_lib_dir(CodeGen *g, Buf *libc_lib_dir) {
|
||||
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) {
|
||||
|
|
@ -3710,7 +3717,7 @@ static void generate_h_file(CodeGen *g) {
|
|||
|
||||
static const char *get_libc_file(CodeGen *g, const char *file) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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_out_type(CodeGen *codegen, OutType out_type);
|
||||
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_root_code(CodeGen *g, Buf *source_dir, Buf *source_basename, Buf *source_code);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@
|
|||
|
||||
#define ZIG_HEADERS_DIR "@CMAKE_INSTALL_PREFIX@/@C_HEADERS_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
|
||||
|
||||
|
|
|
|||
18
src/main.cpp
18
src/main.cpp
|
|
@ -28,7 +28,8 @@ static int usage(const char *arg0) {
|
|||
" --output [file] override destination path\n"
|
||||
" --verbose turn on compiler debug output\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"
|
||||
" --libc-include-dir [path] set the C compiler data path\n"
|
||||
" -isystem [dir] add additional search path for other .h files\n"
|
||||
" -dirafter [dir] same as -isystem but do it last\n"
|
||||
" --library-path [dir] add a directory to the library search path\n"
|
||||
|
|
@ -55,7 +56,8 @@ int main(int argc, char **argv) {
|
|||
const char *out_name = nullptr;
|
||||
bool verbose = false;
|
||||
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 *> lib_dirs = {0};
|
||||
int err;
|
||||
|
|
@ -102,8 +104,10 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
} else if (strcmp(arg, "--name") == 0) {
|
||||
out_name = argv[i];
|
||||
} else if (strcmp(arg, "--libc-path") == 0) {
|
||||
libc_path = argv[i];
|
||||
} else if (strcmp(arg, "--libc-lib-dir") == 0) {
|
||||
libc_lib_dir = argv[i];
|
||||
} else if (strcmp(arg, "--libc-include-dir") == 0) {
|
||||
libc_include_dir = argv[i];
|
||||
} else if (strcmp(arg, "-isystem") == 0) {
|
||||
clang_argv.append("-isystem");
|
||||
clang_argv.append(argv[i]);
|
||||
|
|
@ -182,8 +186,10 @@ int main(int argc, char **argv) {
|
|||
codegen_set_out_type(g, out_type);
|
||||
if (out_name)
|
||||
codegen_set_out_name(g, buf_create_from_str(out_name));
|
||||
if (libc_path)
|
||||
codegen_set_libc_path(g, buf_create_from_str(libc_path));
|
||||
if (libc_lib_dir)
|
||||
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_errmsg_color(g, color);
|
||||
|
||||
|
|
|
|||
|
|
@ -1413,7 +1413,7 @@ int parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const ch
|
|||
clang_argv.append(ZIG_HEADERS_DIR);
|
||||
|
||||
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) {
|
||||
clang_argv.append(codegen->clang_argv[i]);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue