using Clang
using Gnuastro_jll, WCS_jll, GSL_jll, CFITSIO_jll
const CFITSIO_INCLUDE = joinpath(dirname(CFITSIO_jll.libcfitsio_path), "..", "include") |> normpath
const GSL_INCLUDE = joinpath(dirname(GSL_jll.libgsl_path), "..", "include") |> normpath
const WCS_INCLUDE = joinpath(dirname(WCS_jll.libwcs_path), "..", "include") |> normpath
const GNUASTRO_INCLUDE = joinpath(dirname(Gnuastro_jll.libgnuastro_path), "..", "include") |> normpath
const GNUASTRO_HEADERS = [joinpath(GNUASTRO_INCLUDE, "gnuastro", header) for header in readdir(joinpath(GNUASTRO_INCLUDE, "gnuastro")) if endswith(header, ".h")]
wc = init(; headers = GNUASTRO_HEADERS,
output_file = joinpath(@__DIR__, "libgnuastro_api.jl"),
common_file = joinpath(@__DIR__, "libgnuastro_common.jl"),
clang_includes = [GNUASTRO_INCLUDE, CFITSIO_INCLUDE, GSL_INCLUDE, WCS_INCLUDE, CLANG_INCLUDE],
clang_args = ["-I", joinpath(GNUASTRO_INCLUDE, "gnuastro"),
map(x->"-I"*x, find_std_headers())...],
header_wrapped = (root, current)->root == current,
header_library = x->"libgnuastro",
clang_diagnostics = true,
)
run(wc)
This basically works, except the error: unknown type name 'xxx' error. After some investigation, it looks like Gnuastro did this intentionally, since Clang.jl currently has limitations for supporting multi-platform, you need to patch this yourself.
/* Define system specific types. For example `size_t' is 4 and 8 bytes on
32 and 64 bit systems respectively. In both cases, the standard defines
`size_t' to be unsigned. A similar case exists for `long', but it is
signed. During `./configure' the sizeof `size_t' and `long' were found
and are used to define an alias for these system specific types.
Note: we are not using `else'. This is done because by any chance, if
the length of these types is not what is expected (4 or 8), then the
aliases are not defined and the compiler will crash. */
#if GAL_CONFIG_SIZEOF_SIZE_T == 4
#define GAL_TYPE_SIZE_T GAL_TYPE_UINT32
#elif GAL_CONFIG_SIZEOF_SIZE_T == 8
#define GAL_TYPE_SIZE_T GAL_TYPE_UINT64
#endif
#if GAL_CONFIG_SIZEOF_LONG == 4
#define GAL_TYPE_LONG GAL_TYPE_INT32
#define GAL_TYPE_ULONG GAL_TYPE_UINT32
#elif GAL_CONFIG_SIZEOF_LONG == 8
#define GAL_TYPE_LONG GAL_TYPE_INT64
#define GAL_TYPE_ULONG GAL_TYPE_UINT64
#endif
To get rid of all of the error: unknown type name 'xxx' errors, a dirty fix would be manually add #include <stddef.h> to config.h, array.h, polygon.h, qsort.h, pointer.h, box.h and add #include <gnuastro/list.h> to array.h.
I posted the generated wrappers here: LibGnuastro.jl ยท GitHub