Skip to content

Commit 167f82d

Browse files
jmillikin3405691582
andcommitted
Support building on OpenBSD.
Closes: #11 Co-Authored-By: 3405691582 <[email protected]> GitOrigin-RevId: 19dc23f2d6f3695ac3089739747b67389993042f
1 parent 5b1702c commit 167f82d

File tree

5 files changed

+248
-0
lines changed

5 files changed

+248
-0
lines changed
+213
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
{GNULIB_CONFIG_HEADER}
2+
3+
#define _GL_ATTRIBUTE_FORMAT_PRINTF(x, y)
4+
5+
#define O_BINARY 0
6+
#define O_TEXT 0
7+
8+
extern char **environ;
9+
10+
/******************************************************************************/
11+
12+
#define CHECK_PRINTF_SAFE 1
13+
#define C_LOCALE_MAYBE_EILSEQ 1
14+
#define DBL_EXPBIT0_BIT 20
15+
#define DBL_EXPBIT0_WORD 1
16+
#define FLT_EXPBIT0_BIT 23
17+
#define FLT_EXPBIT0_WORD 0
18+
#define FUNC_REALPATH_WORKS 1
19+
#define GETTIMEOFDAY_TIMEZONE struct timezone
20+
#define GNULIB_CANONICALIZE_LGPL 1
21+
#define GNULIB_CLOSE_STREAM 1
22+
#define GNULIB_DIRNAME 1
23+
#define GNULIB_FD_SAFER_FLAG 1
24+
#define GNULIB_FOPEN_SAFER 1
25+
#define GNULIB_FSCANF 1
26+
#define GNULIB_LOCK 1
27+
#define GNULIB_MALLOC_GNU 1
28+
#define GNULIB_MSVC_NOTHROW 1
29+
#define GNULIB_PIPE2_SAFER 1
30+
#define GNULIB_SCANF 1
31+
#define GNULIB_SNPRINTF 1
32+
#define GNULIB_STRERROR 1
33+
#define GNULIB_STRERROR_R_POSIX 1
34+
#define HAVE_ALLOCA 1
35+
#define HAVE_CALLOC_POSIX 1
36+
#define HAVE_CANONICALIZE_FILE_NAME 1
37+
#define HAVE_CATGETS 1
38+
#define HAVE_CLOCK_GETTIME 1
39+
#define HAVE_CLOCK_SETTIME 1
40+
#define HAVE_DECL_ALARM 1
41+
#define HAVE_DECL_CLEARERR_UNLOCKED 0
42+
#define HAVE_DECL_FEOF_UNLOCKED 0
43+
#define HAVE_DECL_FERROR_UNLOCKED 0
44+
#define HAVE_DECL_FFLUSH_UNLOCKED 0
45+
#define HAVE_DECL_FGETS_UNLOCKED 1
46+
#define HAVE_DECL_FPUTC_UNLOCKED 0
47+
#define HAVE_DECL_FPUTS_UNLOCKED 0
48+
#define HAVE_DECL_FREAD_UNLOCKED 0
49+
#define HAVE_DECL_FWRITE_UNLOCKED 0
50+
#define HAVE_DECL_GETCHAR_UNLOCKED 1
51+
#define HAVE_DECL_GETC_UNLOCKED 1
52+
#define HAVE_DECL_GETDTABLESIZE 1
53+
#define HAVE_DECL_GETHRTIME 0
54+
#define HAVE_DECL_MBSWIDTH_IN_WCHAR_H 0
55+
#define HAVE_DECL_OBSTACK_PRINTF 1
56+
#define HAVE_DECL_PROGRAM_INVOCATION_NAME 0
57+
#define HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME 0
58+
#define HAVE_DECL_PUTCHAR_UNLOCKED 1
59+
#define HAVE_DECL_PUTC_UNLOCKED 1
60+
#define HAVE_DECL_SETENV 1
61+
#define HAVE_DECL_SNPRINTF 1
62+
#define HAVE_DECL_STRDUP 1
63+
#define HAVE_DECL_STRERROR_R 1
64+
#define HAVE_DECL_STRNDUP 1
65+
#define HAVE_DECL_STRNLEN 1
66+
#define HAVE_DECL_UNSETENV 1
67+
#define HAVE_DECL_VSNPRINTF 1
68+
#define HAVE_DECL_WCWIDTH 1
69+
#define HAVE_DECL__SNPRINTF 0
70+
#define HAVE_DECL___ARGV 0
71+
#define HAVE_DUP2 1
72+
#define HAVE_ENVIRON_DECL 1
73+
#define HAVE_FCNTL 1
74+
#define HAVE_FREXPL_IN_LIBC 1
75+
#define HAVE_FREXP_IN_LIBC 1
76+
#define HAVE_GETCWD 1
77+
#define HAVE_GETDTABLESIZE 1
78+
#define HAVE_GETOPT_H 1
79+
#define HAVE_GETOPT_LONG_ONLY 1
80+
#define HAVE_GETRUSAGE 1
81+
#define HAVE_GETTIMEOFDAY 1
82+
#define HAVE_INTMAX_T 1
83+
#define HAVE_INTTYPES_H 1
84+
#define HAVE_INTTYPES_H_WITH_UINTMAX 1
85+
#define HAVE_ISASCII 1
86+
#define HAVE_ISNAND_IN_LIBC 1
87+
#define HAVE_ISNANF_IN_LIBC 1
88+
#define HAVE_ISNANL_IN_LIBC 1
89+
#define HAVE_ISWCNTRL 1
90+
#define HAVE_LANGINFO_CODESET 1
91+
#define HAVE_LDEXPL 1
92+
#define HAVE_LDEXPL_IN_LIBC 1
93+
#define HAVE_LDEXP_IN_LIBC 1
94+
#define HAVE_LIMITS_H 1
95+
#define HAVE_LINK 1
96+
#define HAVE_LONG_LONG_INT 1
97+
#define HAVE_LSTAT 1
98+
#define HAVE_MALLOC_GNU 1
99+
#define HAVE_MALLOC_POSIX 1
100+
#define HAVE_MAP_ANONYMOUS 1
101+
#define HAVE_MATH_H 1
102+
#define HAVE_MBRTOWC 1
103+
#define HAVE_MBSINIT 1
104+
#define HAVE_MBSTATE_T 1
105+
#define HAVE_MEMORY_H 1
106+
#define HAVE_MINMAX_IN_SYS_PARAM_H 1
107+
#define HAVE_MPROTECT 1
108+
#define HAVE_OBSTACK_PRINTF 1
109+
#define HAVE_PIPE 1
110+
#define HAVE_PIPE2 1
111+
#define HAVE_POSIX_SPAWN 1
112+
#define HAVE_POSIX_SPAWNATTR_T 1
113+
#define HAVE_POSIX_SPAWN_FILE_ACTIONS_T 1
114+
#define HAVE_PTHREAD_MUTEX_RECURSIVE 1
115+
#define HAVE_PTHREAD_RWLOCK 1
116+
#define HAVE_RAISE 1
117+
#define HAVE_RAWMEMCHR 1
118+
#define HAVE_READLINK 1
119+
#define HAVE_READLINKAT 1
120+
#define HAVE_REALLOC_POSIX 1
121+
#define HAVE_REALPATH 1
122+
#define HAVE_SEARCH_H 1
123+
#define HAVE_SETENV 1
124+
#define HAVE_SIGACTION 1
125+
#define HAVE_SIGALTSTACK 1
126+
#define HAVE_SIGINTERRUPT 1
127+
#define HAVE_SIGSET_T 1
128+
#define HAVE_SIG_ATOMIC_T 1
129+
#define HAVE_SNPRINTF 0
130+
#define HAVE_SNPRINTF_RETVAL_C99 1
131+
#define HAVE_SPAWN_H 1
132+
#define HAVE_STDINT_H 1
133+
#define HAVE_STDINT_H_WITH_UINTMAX 1
134+
#define HAVE_STDLIB_H 1
135+
#define HAVE_STPCPY 1
136+
#define HAVE_STRCHRNUL 1
137+
#define HAVE_STRDUP 1
138+
#define HAVE_STRERROR_R 1
139+
#define HAVE_STRINGS_H 1
140+
#define HAVE_STRING_H 1
141+
#define HAVE_STRNDUP 1
142+
#define HAVE_STRNLEN 1
143+
#define HAVE_STRUCT_SIGACTION_SA_SIGACTION 1
144+
#define HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC 1
145+
#define HAVE_STRUCT_TMS 1
146+
#define HAVE_STRVERSCMP 1
147+
#define HAVE_SYMLINK 1
148+
#define HAVE_SYS_CDEFS_H 1
149+
#define HAVE_SYS_MMAN_H 1
150+
#define HAVE_SYS_PARAM_H 1
151+
#define HAVE_SYS_RESOURCE_H 1
152+
#define HAVE_SYS_SOCKET_H 1
153+
#define HAVE_SYS_STAT_H 1
154+
#define HAVE_SYS_TIMES_H 1
155+
#define HAVE_SYS_TIME_H 1
156+
#define HAVE_SYS_TYPES_H 1
157+
#define HAVE_SYS_WAIT_H 1
158+
#define HAVE_TOWLOWER 1
159+
#define HAVE_TSEARCH 1
160+
#define HAVE_UNISTD_H 1
161+
#define HAVE_UNSETENV 1
162+
#define HAVE_UNSIGNED_LONG_LONG_INT 1
163+
#define HAVE_VAR___PROGNAME 1
164+
#define HAVE_VSNPRINTF 1
165+
#define HAVE_WAITID 1
166+
#define HAVE_WCHAR_H 1
167+
#define HAVE_WCHAR_T 1
168+
#define HAVE_WCRTOMB 1
169+
#define HAVE_WCSLEN 1
170+
#define HAVE_WCSNLEN 1
171+
#define HAVE_WCTYPE_H 1
172+
#define HAVE_WCWIDTH 1
173+
#define HAVE_WINT_T 1
174+
#define HAVE_WORKING_O_NOATIME 0
175+
#define HAVE_WORKING_O_NOFOLLOW 1
176+
#define HAVE__BOOL 1
177+
#define HAVE___XPG_STRERROR_R 1
178+
#define INSTALLPREFIX "/usr/local"
179+
#define LSTAT_FOLLOWS_SLASHED_SYMLINK 1
180+
#define MALLOC_0_IS_NONNULL 1
181+
# define __USE_MINGW_ANSI_STDIO 1
182+
#define PROMOTED_MODE_T mode_t
183+
#define REPLACE_FPRINTF_POSIX 1
184+
#define REPLACE_PRINTF_POSIX 1
185+
#define REPLACE_VFPRINTF_POSIX 1
186+
#define STDC_HEADERS 1
187+
#define TYPEOF_STRUCT_STAT_ST_ATIM_IS_STRUCT_TIMESPEC 1
188+
#define USER_LABEL_PREFIX
189+
#define USE_POSIX_THREADS 1
190+
#define USE_POSIX_THREADS_WEAK 1
191+
# define _ALL_SOURCE 1
192+
# define _DARWIN_C_SOURCE 1
193+
# define _GNU_SOURCE 1
194+
# define _NETBSD_SOURCE 1
195+
# define _OPENBSD_SOURCE 1
196+
# define _POSIX_PTHREAD_SEMANTICS 1
197+
# define __STDC_WANT_IEC_60559_ATTRIBS_EXT__ 1
198+
# define __STDC_WANT_IEC_60559_BFP_EXT__ 1
199+
# define __STDC_WANT_IEC_60559_DFP_EXT__ 1
200+
# define __STDC_WANT_IEC_60559_FUNCS_EXT__ 1
201+
# define __STDC_WANT_IEC_60559_TYPES_EXT__ 1
202+
# define __STDC_WANT_LIB_EXT2__ 1
203+
# define __STDC_WANT_MATH_SPEC_FUNCS__ 1
204+
# define _TANDEM_SOURCE 1
205+
# define _HPUX_ALT_XOPEN_SOCKET_API 1
206+
# define __EXTENSIONS__ 1
207+
#define USE_UNLOCKED_IO 0
208+
#define _DARWIN_USE_64_BIT_INODE 1
209+
#define _NETBSD_SOURCE 1
210+
#define _USE_STD_STAT 1
211+
#define restrict __restrict
212+
213+
{GNULIB_CONFIG_FOOTER}

bison/internal/gnulib/gnulib.BUILD

+11
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ cc_library(
1919
hdrs = select({
2020
"@bazel_tools//src/conditions:darwin": glob(["config-darwin/*.h"]),
2121
"@bazel_tools//src/conditions:windows": glob(["config-windows/*.h"]),
22+
"@bazel_tools//src/conditions:openbsd": glob(["config-openbsd/*.h"]),
2223
"//conditions:default": glob(["config-linux/*.h"]),
2324
}),
2425
includes = select({
@@ -28,6 +29,9 @@ cc_library(
2829
"@bazel_tools//src/conditions:windows": [
2930
"config-windows",
3031
],
32+
"@bazel_tools//src/conditions:openbsd": [
33+
"config-openbsd",
34+
],
3135
"//conditions:default": [
3236
"config-linux",
3337
],
@@ -42,6 +46,12 @@ cc_library(
4246
deps = [":config_h"],
4347
)
4448

49+
cc_library(
50+
name = "stub_alloca_h",
51+
hdrs = ["stub-alloca/alloca.h"],
52+
includes = ["stub-alloca"],
53+
)
54+
4555
_GNULIB_HDRS = glob([
4656
"lib/*.h",
4757
"lib/bitset/*.h",
@@ -192,6 +202,7 @@ cc_library(
192202
"//:timevar_def",
193203
] + select({
194204
"@bazel_tools//src/conditions:windows": [":gnulib_windows_shims"],
205+
"@bazel_tools//src/conditions:openbsd": [":stub_alloca_h"],
195206
"//conditions:default": [],
196207
}),
197208
)

bison/internal/gnulib/gnulib.bzl

+16
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ _CONFIG_FOOTER = """
4545
#include <stdint.h>
4646
#include <stdio.h>
4747
#include <wchar.h>
48+
#include <stdarg.h>
4849
4950
struct obstack;
5051
int obstack_printf(struct obstack *obs, const char *format, ...);
@@ -78,6 +79,7 @@ def gnulib_overlay(ctx, bison_version, extra_copts = []):
7879
("darwin", ctx.attr._gnulib_config_darwin_h),
7980
("linux", ctx.attr._gnulib_config_linux_h),
8081
("windows", ctx.attr._gnulib_config_windows_h),
82+
("openbsd", ctx.attr._gnulib_config_openbsd_h),
8183
]:
8284
config_prefix = "gnulib/config-{}/".format(os)
8385

@@ -143,6 +145,20 @@ def gnulib_overlay(ctx, bison_version, extra_copts = []):
143145
"(const char **) environ": "NULL",
144146
}, executable = False)
145147

148+
# Some platforms have alloca() but not <alloca.h>.
149+
ctx.file("gnulib/stub-alloca/alloca.h", "")
150+
151+
# Silence warning about unused variable when HAVE_SNPRINTF is defined 0.
152+
ctx.template("gnulib/lib/vasnprintf.c", "gnulib/lib/vasnprintf.c", substitutions = {
153+
"int flags = dp->flags;": "int flags = dp->flags; (void)flags;",
154+
})
155+
156+
# Silence warning about comparison of `size_t` to `float`.
157+
ctx.template("gnulib/lib/hash.c", "gnulib/lib/hash.c", substitutions = {
158+
"(SIZE_MAX <= candidate)": "((float)(SIZE_MAX) <= candidate)",
159+
"(SIZE_MAX <= new_candidate)": "((float)(SIZE_MAX) <= new_candidate)",
160+
})
161+
146162
_WINDOWS_STDLIB_SHIMS = [
147163
"alloca",
148164
"errno",

bison/internal/repository.bzl

+4
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,9 @@ bison_repository = repository_rule(
133133
default = "//bison/internal:gnulib/config-windows.h",
134134
allow_single_file = True,
135135
),
136+
"_gnulib_config_openbsd_h": attr.label(
137+
default = "//bison/internal:gnulib/config-openbsd.h",
138+
allow_single_file = True,
139+
),
136140
},
137141
)

tests/BUILD

+4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ cc_test(
7171
name = "bison_test",
7272
srcs = ["bison_test.cc"],
7373
data = [":testdata"],
74+
linkstatic = select({
75+
"@bazel_tools//src/conditions:openbsd": True,
76+
"//conditions:default": None,
77+
}),
7478
deps = [
7579
"@bazel_tools//tools/cpp/runfiles",
7680
"@com_google_googletest//:gtest",

0 commit comments

Comments
 (0)