Skip to content

Commit

Permalink
devel/wasi-libc: refresh std{arg,def} headers from LLVM 18
Browse files Browse the repository at this point in the history
  • Loading branch information
vishwin committed Mar 27, 2024
1 parent 1df4d47 commit b787213
Show file tree
Hide file tree
Showing 19 changed files with 458 additions and 102 deletions.
11 changes: 6 additions & 5 deletions devel/wasi-libc/Makefile
@@ -1,6 +1,7 @@
PORTNAME= wasi-libc
DISTVERSIONPREFIX= wasi-sdk-
DISTVERSION= 21
PORTREVISION= 1
CATEGORIES= devel

MAINTAINER= vishwin@FreeBSD.org
Expand All @@ -26,9 +27,6 @@ ALL_TARGET= finish
# NOTE: matches the https://github.com/WebAssembly/wasi-sdk
WASI_SYSROOT= ${PREFIX}/share/wasi-sysroot

# NOTE: our llvm ports don't ship stdarg/stddef clang headers, so they're in FILESDIR
# and we install them to the sysroot

MAKE_ENV= INSTALL_DIR=${STAGEDIR}${WASI_SYSROOT} \
EXTRA_CFLAGS="-O2 -DNDEBUG -isystem ${FILESDIR}" \
AR=${LOCALBASE}/bin/llvm-ar${LLVM_VERSION} \
Expand All @@ -40,7 +38,10 @@ post-patch:
${REINPLACE_CMD} -e 's|install: finish|install:|' ${WRKSRC}/Makefile

post-install:
${INSTALL_DATA} ${FILESDIR}/stdarg.h ${STAGEDIR}${WASI_SYSROOT}/include/
${INSTALL_DATA} ${FILESDIR}/stddef.h ${STAGEDIR}${WASI_SYSROOT}/include/
# NOTE: our llvm ports don't ship stdarg/stddef clang headers, so
# they are copied from clang/lib/Headers into FILESDIR and we install
# them to the sysroot
${INSTALL_DATA} ${FILESDIR}/*stdarg*.h ${STAGEDIR}${WASI_SYSROOT}/include/
${INSTALL_DATA} ${FILESDIR}/*stddef*.h ${STAGEDIR}${WASI_SYSROOT}/include/

.include <bsd.port.mk>
13 changes: 13 additions & 0 deletions devel/wasi-libc/files/__stdarg___gnuc_va_list.h
@@ -0,0 +1,13 @@
/*===---- __stdarg___gnuc_va_list.h - Definition of __gnuc_va_list ---------===
*
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*===-----------------------------------------------------------------------===
*/

#ifndef __GNUC_VA_LIST
#define __GNUC_VA_LIST
typedef __builtin_va_list __gnuc_va_list;
#endif
12 changes: 12 additions & 0 deletions devel/wasi-libc/files/__stdarg___va_copy.h
@@ -0,0 +1,12 @@
/*===---- __stdarg___va_copy.h - Definition of __va_copy -------------------===
*
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*===-----------------------------------------------------------------------===
*/

#ifndef __va_copy
#define __va_copy(d, s) __builtin_va_copy(d, s)
#endif
22 changes: 22 additions & 0 deletions devel/wasi-libc/files/__stdarg_va_arg.h
@@ -0,0 +1,22 @@
/*===---- __stdarg_va_arg.h - Definitions of va_start, va_arg, va_end-------===
*
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*===-----------------------------------------------------------------------===
*/

#ifndef va_arg

#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
/* C23 does not require the second parameter for va_start. */
#define va_start(ap, ...) __builtin_va_start(ap, 0)
#else
/* Versions before C23 do require the second parameter. */
#define va_start(ap, param) __builtin_va_start(ap, param)
#endif
#define va_end(ap) __builtin_va_end(ap)
#define va_arg(ap, type) __builtin_va_arg(ap, type)

#endif
12 changes: 12 additions & 0 deletions devel/wasi-libc/files/__stdarg_va_copy.h
@@ -0,0 +1,12 @@
/*===---- __stdarg_va_copy.h - Definition of va_copy------------------------===
*
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*===-----------------------------------------------------------------------===
*/

#ifndef va_copy
#define va_copy(dest, src) __builtin_va_copy(dest, src)
#endif
13 changes: 13 additions & 0 deletions devel/wasi-libc/files/__stdarg_va_list.h
@@ -0,0 +1,13 @@
/*===---- __stdarg_va_list.h - Definition of va_list -----------------------===
*
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*===-----------------------------------------------------------------------===
*/

#ifndef _VA_LIST
#define _VA_LIST
typedef __builtin_va_list va_list;
#endif
27 changes: 27 additions & 0 deletions devel/wasi-libc/files/__stddef_max_align_t.h
@@ -0,0 +1,27 @@
/*===---- __stddef_max_align_t.h - Definition of max_align_t ---------------===
*
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*===-----------------------------------------------------------------------===
*/

#ifndef __CLANG_MAX_ALIGN_T_DEFINED
#define __CLANG_MAX_ALIGN_T_DEFINED

#if defined(_MSC_VER)
typedef double max_align_t;
#elif defined(__APPLE__)
typedef long double max_align_t;
#else
// Define 'max_align_t' to match the GCC definition.
typedef struct {
long long __clang_max_align_nonce1
__attribute__((__aligned__(__alignof__(long long))));
long double __clang_max_align_nonce2
__attribute__((__aligned__(__alignof__(long double))));
} max_align_t;
#endif

#endif
29 changes: 29 additions & 0 deletions devel/wasi-libc/files/__stddef_null.h
@@ -0,0 +1,29 @@
/*===---- __stddef_null.h - Definition of NULL -----------------------------===
*
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*===-----------------------------------------------------------------------===
*/

#if !defined(NULL) || !__building_module(_Builtin_stddef)

/* linux/stddef.h will define NULL to 0. glibc (and other) headers then define
* __need_NULL and rely on stddef.h to redefine NULL to the correct value again.
* Modules don't support redefining macros like that, but support that pattern
* in the non-modules case.
*/
#undef NULL

#ifdef __cplusplus
#if !defined(__MINGW32__) && !defined(_MSC_VER)
#define NULL __null
#else
#define NULL 0
#endif
#else
#define NULL ((void*)0)
#endif

#endif
29 changes: 29 additions & 0 deletions devel/wasi-libc/files/__stddef_nullptr_t.h
@@ -0,0 +1,29 @@
/*===---- __stddef_nullptr_t.h - Definition of nullptr_t -------------------===
*
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*===-----------------------------------------------------------------------===
*/

/*
* When -fbuiltin-headers-in-system-modules is set this is a non-modular header
* and needs to behave as if it was textual.
*/
#if !defined(_NULLPTR_T) || \
(__has_feature(modules) && !__building_module(_Builtin_stddef))
#define _NULLPTR_T

#ifdef __cplusplus
#if defined(_MSC_EXTENSIONS) && defined(_NATIVE_NULLPTR_SUPPORTED)
namespace std {
typedef decltype(nullptr) nullptr_t;
}
using ::std::nullptr_t;
#endif
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
typedef typeof(nullptr) nullptr_t;
#endif

#endif
17 changes: 17 additions & 0 deletions devel/wasi-libc/files/__stddef_offsetof.h
@@ -0,0 +1,17 @@
/*===---- __stddef_offsetof.h - Definition of offsetof ---------------------===
*
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*===-----------------------------------------------------------------------===
*/

/*
* When -fbuiltin-headers-in-system-modules is set this is a non-modular header
* and needs to behave as if it was textual.
*/
#if !defined(offsetof) || \
(__has_feature(modules) && !__building_module(_Builtin_stddef))
#define offsetof(t, d) __builtin_offsetof(t, d)
#endif
20 changes: 20 additions & 0 deletions devel/wasi-libc/files/__stddef_ptrdiff_t.h
@@ -0,0 +1,20 @@
/*===---- __stddef_ptrdiff_t.h - Definition of ptrdiff_t -------------------===
*
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*===-----------------------------------------------------------------------===
*/

/*
* When -fbuiltin-headers-in-system-modules is set this is a non-modular header
* and needs to behave as if it was textual.
*/
#if !defined(_PTRDIFF_T) || \
(__has_feature(modules) && !__building_module(_Builtin_stddef))
#define _PTRDIFF_T

typedef __PTRDIFF_TYPE__ ptrdiff_t;

#endif
20 changes: 20 additions & 0 deletions devel/wasi-libc/files/__stddef_rsize_t.h
@@ -0,0 +1,20 @@
/*===---- __stddef_rsize_t.h - Definition of rsize_t -----------------------===
*
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*===-----------------------------------------------------------------------===
*/

/*
* When -fbuiltin-headers-in-system-modules is set this is a non-modular header
* and needs to behave as if it was textual.
*/
#if !defined(_RSIZE_T) || \
(__has_feature(modules) && !__building_module(_Builtin_stddef))
#define _RSIZE_T

typedef __SIZE_TYPE__ rsize_t;

#endif
20 changes: 20 additions & 0 deletions devel/wasi-libc/files/__stddef_size_t.h
@@ -0,0 +1,20 @@
/*===---- __stddef_size_t.h - Definition of size_t -------------------------===
*
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*===-----------------------------------------------------------------------===
*/

/*
* When -fbuiltin-headers-in-system-modules is set this is a non-modular header
* and needs to behave as if it was textual.
*/
#if !defined(_SIZE_T) || \
(__has_feature(modules) && !__building_module(_Builtin_stddef))
#define _SIZE_T

typedef __SIZE_TYPE__ size_t;

#endif
17 changes: 17 additions & 0 deletions devel/wasi-libc/files/__stddef_unreachable.h
@@ -0,0 +1,17 @@
/*===---- __stddef_unreachable.h - Definition of unreachable ---------------===
*
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*===-----------------------------------------------------------------------===
*/

/*
* When -fbuiltin-headers-in-system-modules is set this is a non-modular header
* and needs to behave as if it was textual.
*/
#if !defined(unreachable) || \
(__has_feature(modules) && !__building_module(_Builtin_stddef))
#define unreachable() __builtin_unreachable()
#endif
28 changes: 28 additions & 0 deletions devel/wasi-libc/files/__stddef_wchar_t.h
@@ -0,0 +1,28 @@
/*===---- __stddef_wchar.h - Definition of wchar_t -------------------------===
*
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*===-----------------------------------------------------------------------===
*/

#if !defined(__cplusplus) || (defined(_MSC_VER) && !_NATIVE_WCHAR_T_DEFINED)

/*
* When -fbuiltin-headers-in-system-modules is set this is a non-modular header
* and needs to behave as if it was textual.
*/
#if !defined(_WCHAR_T) || \
(__has_feature(modules) && !__building_module(_Builtin_stddef))
#define _WCHAR_T

#ifdef _MSC_EXTENSIONS
#define _WCHAR_T_DEFINED
#endif

typedef __WCHAR_TYPE__ wchar_t;

#endif

#endif
15 changes: 15 additions & 0 deletions devel/wasi-libc/files/__stddef_wint_t.h
@@ -0,0 +1,15 @@
/*===---- __stddef_wint.h - Definition of wint_t ---------------------------===
*
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*===-----------------------------------------------------------------------===
*/

#ifndef _WINT_T
#define _WINT_T

typedef __WINT_TYPE__ wint_t;

#endif

0 comments on commit b787213

Please sign in to comment.