[all] Reference headers in src instead of copying

This is the second of two big changes to clean up includes throughout
the project. Since I've started using clangd with Neovim and using
VSCode's intellisense, my former strategy of copying all header files
into place in `build/include` means that the real files don't show up in
`compile_commands.json` and so display many include errors when viewing
those header files in those tools.

That setup was mostly predicated on a desire to keep directory depths
small, but really I don't think paths like `src/libraries/j6/j6` are
much better than `src/libraries/j6/include/j6`, and the latter doesn't
have the aforementioned issues, and is clearer to the casual observer as
well.

Some additional changes:

- Added a new module flag `copy_headers` for behavior similar to the old
  style, but placing headers in `$module_dir/include` instead of the
  global `build/include`. This was needed for external projects that
  don't follow the same source/headers folder structure - in this case,
  `zstd`.
- There is no longer an associated `headers.*.ninja` for each
  `module.*.ninja` file, as only parsed headers need to be listed; this
  functionality has been moved back into the module's ninja file.
This commit is contained in:
Justin C. Miller
2023-07-12 19:45:43 -07:00
parent f5208d1641
commit 5d1fdd0e81
98 changed files with 62 additions and 74 deletions

View File

@@ -14,4 +14,4 @@ bp = module("bootproto",
from os.path import join
layout = join(source_root, "definitions/memory_layout.yaml")
bp.add_depends("bootproto/memory.h.cog", deps=[layout])
bp.add_depends(["bootproto/memory.h.cog"], deps=[layout])

View File

@@ -15,4 +15,4 @@ void *memset(void *s, int c, size_t n);
#ifdef __cplusplus
} // extern "C"
#endif
#endif

View File

@@ -13,6 +13,7 @@
#include <__j6libc/null.h>
#include <__j6libc/restrict.h>
#include <__j6libc/size_t.h>
#include <j6/memutils.h> // memcpy, memmove, memset are defined in libj6
#ifdef __cplusplus
extern "C" {
@@ -20,8 +21,6 @@ extern "C" {
// Copying functions
//
void *memcpy(void * restrict s1, const void * restrict s2, size_t n);
void *memmove(void * restrict s1, const void * restrict s2, size_t n);
char *strncpy(char * restrict s1, const char * restrict s2, size_t n);
// Concatenation functions
@@ -49,7 +48,6 @@ char *strtok(char * restrict s1, const char * restrict s2);
// Miscellaneous functions
//
void *memset(void *s, int c, size_t n);
char *strerror(int errnum);
size_t strlen(const char *s);

View File

@@ -5,14 +5,16 @@
# many files that it's unweildy. So if a file is added or removed in
# libc, remember to run configure again.
def glob(ext):
def glob(ext, root=''):
from glob import glob
from pathlib import Path
base = Path(module_root) / root
def resolve(path):
from pathlib import Path
return str(Path(path).relative_to(module_root))
return str(Path(path).relative_to(base))
return list(map(resolve, glob(f"{module_root}/**/*.{ext}", recursive=True)))
return list(map(resolve, glob(f"{base}/**/*.{ext}", recursive=True)))
sources = []
for ext in ("c", "cpp", "s", "inc"):
@@ -20,7 +22,7 @@ for ext in ("c", "cpp", "s", "inc"):
headers = []
for ext in ("h",):
headers += glob(ext) + glob(ext + ".cog")
headers += glob(ext, "include") + glob(ext + ".cog", "include")
libc = module("libc",
kind = "lib",

View File

@@ -90,4 +90,4 @@ template<typename T> T&& forward(typename types::remove_reference<T>::type& par
template<typename T> void swap(T &t1, T &t2) { T tmp = move(t1); t1 = move(t2); t2 = move(tmp); }
} // namespace util
} // namespace util