1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-22 22:40:26 +00:00

Add ipv6, shared, and cryptorand options to meosn.

Allows for builting with cosmopolitan, both with meson
and Makefile. Use:

CC=comsocc meson setup -Dipv6=false -Ddynamic_modules=false
-Dshared=false -Dos_name=cosmopolitan

to configure for cosmopolitan build.
This commit is contained in:
Calvin Rose 2023-11-02 08:51:42 -05:00
parent 3b189eab64
commit df2d5cb3d3
7 changed files with 69 additions and 36 deletions

View File

@ -42,6 +42,7 @@ JANET_DIST_DIR?=janet-dist
JANET_BOOT_FLAGS:=. JANET_PATH '$(JANET_PATH)' JANET_BOOT_FLAGS:=. JANET_PATH '$(JANET_PATH)'
JANET_TARGET_OBJECTS=build/janet.o build/shell.o JANET_TARGET_OBJECTS=build/janet.o build/shell.o
JPM_TAG?=master JPM_TAG?=master
HAS_SHARED?=1
DEBUGGER=gdb DEBUGGER=gdb
SONAME_SETTER=-Wl,-soname, SONAME_SETTER=-Wl,-soname,
@ -98,7 +99,10 @@ ifeq ($(findstring MINGW,$(UNAME)), MINGW)
endif endif
$(shell mkdir -p build/core build/c build/boot build/mainclient) $(shell mkdir -p build/core build/c build/boot build/mainclient)
all: $(JANET_TARGET) $(JANET_LIBRARY) $(JANET_STATIC_LIBRARY) build/janet.h all: $(JANET_TARGET) $(JANET_STATIC_LIBRARY) build/janet.h
ifeq ($(HAS_SHARED), 1)
all: $(JANET_LIBRARY)
endif
###################### ######################
##### Name Files ##### ##### Name Files #####
@ -263,7 +267,7 @@ dist: build/janet-dist.tar.gz
build/janet-%.tar.gz: $(JANET_TARGET) \ build/janet-%.tar.gz: $(JANET_TARGET) \
build/janet.h \ build/janet.h \
janet.1 LICENSE CONTRIBUTING.md $(JANET_LIBRARY) $(JANET_STATIC_LIBRARY) \ janet.1 LICENSE CONTRIBUTING.md $(JANET_STATIC_LIBRARY) \
README.md build/c/janet.c build/c/shell.c README.md build/c/janet.c build/c/shell.c
mkdir -p build/$(JANET_DIST_DIR)/bin mkdir -p build/$(JANET_DIST_DIR)/bin
cp $(JANET_TARGET) build/$(JANET_DIST_DIR)/bin/ cp $(JANET_TARGET) build/$(JANET_DIST_DIR)/bin/
@ -271,13 +275,17 @@ build/janet-%.tar.gz: $(JANET_TARGET) \
mkdir -p build/$(JANET_DIST_DIR)/include mkdir -p build/$(JANET_DIST_DIR)/include
cp build/janet.h build/$(JANET_DIST_DIR)/include/ cp build/janet.h build/$(JANET_DIST_DIR)/include/
mkdir -p build/$(JANET_DIST_DIR)/lib/ mkdir -p build/$(JANET_DIST_DIR)/lib/
cp $(JANET_LIBRARY) $(JANET_STATIC_LIBRARY) build/$(JANET_DIST_DIR)/lib/ cp $(JANET_STATIC_LIBRARY) build/$(JANET_DIST_DIR)/lib/
cp $(JANET_LIBRARY) build/$(JANET_DIST_DIR)/lib/ || true
mkdir -p build/$(JANET_DIST_DIR)/man/man1/ mkdir -p build/$(JANET_DIST_DIR)/man/man1/
cp janet.1 build/$(JANET_DIST_DIR)/man/man1/janet.1 cp janet.1 build/$(JANET_DIST_DIR)/man/man1/janet.1
mkdir -p build/$(JANET_DIST_DIR)/src/ mkdir -p build/$(JANET_DIST_DIR)/src/
cp build/c/janet.c build/c/shell.c build/$(JANET_DIST_DIR)/src/ cp build/c/janet.c build/c/shell.c build/$(JANET_DIST_DIR)/src/
cp CONTRIBUTING.md LICENSE README.md build/$(JANET_DIST_DIR)/ cp CONTRIBUTING.md LICENSE README.md build/$(JANET_DIST_DIR)/
cd build && tar -czvf ../$@ ./$(JANET_DIST_DIR) cd build && tar -czvf ../$@ ./$(JANET_DIST_DIR)
ifeq ($(HAS_SHARED), 1)
build/janet-%.tar.gz: $(JANET_LIBRARY)
endif
######################### #########################
##### Documentation ##### ##### Documentation #####

View File

@ -61,6 +61,7 @@ conf.set('JANET_NO_SOURCEMAPS', not get_option('sourcemaps'))
conf.set('JANET_NO_ASSEMBLER', not get_option('assembler')) conf.set('JANET_NO_ASSEMBLER', not get_option('assembler'))
conf.set('JANET_NO_PEG', not get_option('peg')) conf.set('JANET_NO_PEG', not get_option('peg'))
conf.set('JANET_NO_NET', not get_option('net')) conf.set('JANET_NO_NET', not get_option('net'))
conf.set('JANET_NO_IPV6', not get_option('ipv6'))
conf.set('JANET_NO_EV', not get_option('ev') or get_option('single_threaded')) conf.set('JANET_NO_EV', not get_option('ev') or get_option('single_threaded'))
conf.set('JANET_REDUCED_OS', get_option('reduced_os')) conf.set('JANET_REDUCED_OS', get_option('reduced_os'))
conf.set('JANET_NO_INT_TYPES', not get_option('int_types')) conf.set('JANET_NO_INT_TYPES', not get_option('int_types'))
@ -78,6 +79,7 @@ conf.set('JANET_EV_NO_KQUEUE', not get_option('kqueue'))
conf.set('JANET_NO_INTERPRETER_INTERRUPT', not get_option('interpreter_interrupt')) conf.set('JANET_NO_INTERPRETER_INTERRUPT', not get_option('interpreter_interrupt'))
conf.set('JANET_NO_FFI', not get_option('ffi')) conf.set('JANET_NO_FFI', not get_option('ffi'))
conf.set('JANET_NO_FFI_JIT', not get_option('ffi_jit')) conf.set('JANET_NO_FFI_JIT', not get_option('ffi_jit'))
conf.set('JANET_NO_CRYPTORAND', not get_option('cryptorand'))
if get_option('os_name') != '' if get_option('os_name') != ''
conf.set('JANET_OS_NAME', get_option('os_name')) conf.set('JANET_OS_NAME', get_option('os_name'))
endif endif
@ -182,32 +184,41 @@ if not get_option('single_threaded')
janet_dependencies += thread_dep janet_dependencies += thread_dep
endif endif
# Allow building with no shared library
if cc.has_argument('-fvisibility=hidden') if cc.has_argument('-fvisibility=hidden')
lib_cflags = ['-fvisibility=hidden'] lib_cflags = ['-fvisibility=hidden']
else else
lib_cflags = [] lib_cflags = []
endif endif
libjanet = library('janet', janetc, if get_option('shared')
libjanet = library('janet', janetc,
include_directories : incdir, include_directories : incdir,
dependencies : janet_dependencies, dependencies : janet_dependencies,
version: meson.project_version(), version: meson.project_version(),
soversion: version_parts[0] + '.' + version_parts[1], soversion: version_parts[0] + '.' + version_parts[1],
c_args : lib_cflags, c_args : lib_cflags,
install : true) install : true)
# Extra c flags - adding -fvisibility=hidden matches the Makefile and # Extra c flags - adding -fvisibility=hidden matches the Makefile and
# shaves off about 10k on linux x64, likely similar on other platforms. # shaves off about 10k on linux x64, likely similar on other platforms.
if cc.has_argument('-fvisibility=hidden') if cc.has_argument('-fvisibility=hidden')
extra_cflags = ['-fvisibility=hidden', '-DJANET_DLL_IMPORT'] extra_cflags = ['-fvisibility=hidden', '-DJANET_DLL_IMPORT']
else else
extra_cflags = ['-DJANET_DLL_IMPORT'] extra_cflags = ['-DJANET_DLL_IMPORT']
endif endif
janet_mainclient = executable('janet', mainclient_src, janet_mainclient = executable('janet', mainclient_src,
include_directories : incdir, include_directories : incdir,
dependencies : janet_dependencies, dependencies : janet_dependencies,
link_with: [libjanet], link_with: [libjanet],
c_args : extra_cflags, c_args : extra_cflags,
install : true) install : true)
else
# No shared library
janet_mainclient = executable('janet', mainclient_src, janetc,
include_directories : incdir,
dependencies : janet_dependencies,
c_args : lib_cflags,
install : true)
endif
if meson.is_cross_build() if meson.is_cross_build()
native_cc = meson.get_compiler('c', native: true) native_cc = meson.get_compiler('c', native: true)
@ -271,14 +282,15 @@ endforeach
run_target('repl', command : [janet_nativeclient]) run_target('repl', command : [janet_nativeclient])
# For use as meson subproject (wrap) # For use as meson subproject (wrap)
janet_dep = declare_dependency(include_directories : incdir, if get_option('shared')
janet_dep = declare_dependency(include_directories : incdir,
link_with : libjanet) link_with : libjanet)
# pkgconfig # pkgconfig
pkg = import('pkgconfig') pkg = import('pkgconfig')
pkg.generate(libjanet, pkg.generate(libjanet,
subdirs: 'janet', subdirs: 'janet',
description: 'Library for the Janet programming language.') description: 'Library for the Janet programming language.')
endif
# Installation # Installation
install_man('janet.1') install_man('janet.1')

View File

@ -11,6 +11,7 @@ option('peg', type : 'boolean', value : true)
option('int_types', type : 'boolean', value : true) option('int_types', type : 'boolean', value : true)
option('prf', type : 'boolean', value : false) option('prf', type : 'boolean', value : false)
option('net', type : 'boolean', value : true) option('net', type : 'boolean', value : true)
option('ipv6', type : 'boolean', value : true)
option('ev', type : 'boolean', value : true) option('ev', type : 'boolean', value : true)
option('processes', type : 'boolean', value : true) option('processes', type : 'boolean', value : true)
option('umask', type : 'boolean', value : true) option('umask', type : 'boolean', value : true)
@ -29,3 +30,5 @@ option('stack_max', type : 'integer', min : 8096, max : 0x7fffffff, value : 0x7f
option('arch_name', type : 'string', value: '') option('arch_name', type : 'string', value: '')
option('os_name', type : 'string', value: '') option('os_name', type : 'string', value: '')
option('shared', type : 'boolean', value: true)
option('cryptorand', type : 'boolean', value: true)

View File

@ -52,6 +52,8 @@
/* #define JANET_EV_NO_EPOLL */ /* #define JANET_EV_NO_EPOLL */
/* #define JANET_EV_NO_KQUEUE */ /* #define JANET_EV_NO_KQUEUE */
/* #define JANET_NO_INTERPRETER_INTERRUPT */ /* #define JANET_NO_INTERPRETER_INTERRUPT */
/* #define JANET_NO_IPV6 */
/* #define JANET_NO_CRYPTORAND */
/* Custom vm allocator support */ /* Custom vm allocator support */
/* #include <mimalloc.h> */ /* #include <mimalloc.h> */

View File

@ -955,8 +955,10 @@ static const struct sockopt_type sockopt_type_list[] = {
{ "ip-multicast-ttl", IPPROTO_IP, IP_MULTICAST_TTL, JANET_NUMBER }, { "ip-multicast-ttl", IPPROTO_IP, IP_MULTICAST_TTL, JANET_NUMBER },
{ "ip-add-membership", IPPROTO_IP, IP_ADD_MEMBERSHIP, JANET_POINTER }, { "ip-add-membership", IPPROTO_IP, IP_ADD_MEMBERSHIP, JANET_POINTER },
{ "ip-drop-membership", IPPROTO_IP, IP_DROP_MEMBERSHIP, JANET_POINTER }, { "ip-drop-membership", IPPROTO_IP, IP_DROP_MEMBERSHIP, JANET_POINTER },
#ifndef JANET_NO_IPV6
{ "ipv6-join-group", IPPROTO_IPV6, IPV6_JOIN_GROUP, JANET_POINTER }, { "ipv6-join-group", IPPROTO_IPV6, IPV6_JOIN_GROUP, JANET_POINTER },
{ "ipv6-leave-group", IPPROTO_IPV6, IPV6_LEAVE_GROUP, JANET_POINTER }, { "ipv6-leave-group", IPPROTO_IPV6, IPV6_LEAVE_GROUP, JANET_POINTER },
#endif
{ NULL, 0, 0, JANET_POINTER } { NULL, 0, 0, JANET_POINTER }
}; };
@ -993,7 +995,9 @@ JANET_CORE_FN(cfun_net_setsockopt,
union { union {
int v_int; int v_int;
struct ip_mreq v_mreq; struct ip_mreq v_mreq;
#ifndef JANET_NO_IPV6
struct ipv6_mreq v_mreq6; struct ipv6_mreq v_mreq6;
#endif
} val; } val;
void *optval = (void *)&val; void *optval = (void *)&val;
@ -1011,12 +1015,14 @@ JANET_CORE_FN(cfun_net_setsockopt,
val.v_mreq.imr_interface.s_addr = htonl(INADDR_ANY); val.v_mreq.imr_interface.s_addr = htonl(INADDR_ANY);
inet_pton(AF_INET, addr, &val.v_mreq.imr_multiaddr.s_addr); inet_pton(AF_INET, addr, &val.v_mreq.imr_multiaddr.s_addr);
optlen = sizeof(val.v_mreq); optlen = sizeof(val.v_mreq);
#ifndef JANET_NO_IPV6
} else if (st->optname == IPV6_JOIN_GROUP || st->optname == IPV6_LEAVE_GROUP) { } else if (st->optname == IPV6_JOIN_GROUP || st->optname == IPV6_LEAVE_GROUP) {
const char *addr = janet_getcstring(argv, 2); const char *addr = janet_getcstring(argv, 2);
memset(&val.v_mreq6, 0, sizeof val.v_mreq6); memset(&val.v_mreq6, 0, sizeof val.v_mreq6);
val.v_mreq6.ipv6mr_interface = 0; val.v_mreq6.ipv6mr_interface = 0;
inet_pton(AF_INET6, addr, &val.v_mreq6.ipv6mr_multiaddr); inet_pton(AF_INET6, addr, &val.v_mreq6.ipv6mr_multiaddr);
optlen = sizeof(val.v_mreq6); optlen = sizeof(val.v_mreq6);
#endif
} else { } else {
janet_panicf("invalid socket option type"); janet_panicf("invalid socket option type");
} }

View File

@ -960,6 +960,7 @@ void arc4random_buf(void *buf, size_t nbytes);
#endif #endif
int janet_cryptorand(uint8_t *out, size_t n) { int janet_cryptorand(uint8_t *out, size_t n) {
#ifndef JANET_NO_CRYPTORAND
#ifdef JANET_WINDOWS #ifdef JANET_WINDOWS
for (size_t i = 0; i < n; i += sizeof(unsigned int)) { for (size_t i = 0; i < n; i += sizeof(unsigned int)) {
unsigned int v; unsigned int v;
@ -971,7 +972,10 @@ int janet_cryptorand(uint8_t *out, size_t n) {
} }
} }
return 0; return 0;
#elif defined(JANET_LINUX) || defined(JANET_CYGWIN) || ( defined(JANET_APPLE) && !defined(MAC_OS_X_VERSION_10_7) ) #elif defined(JANET_BSD) || defined(MAC_OS_X_VERSION_10_7)
arc4random_buf(out, n);
return 0;
#else
/* We should be able to call getrandom on linux, but it doesn't seem /* We should be able to call getrandom on linux, but it doesn't seem
to be uniformly supported on linux distros. to be uniformly supported on linux distros.
On Mac, arc4random_buf wasn't available on until 10.7. On Mac, arc4random_buf wasn't available on until 10.7.
@ -993,12 +997,10 @@ int janet_cryptorand(uint8_t *out, size_t n) {
} }
RETRY_EINTR(rc, close(randfd)); RETRY_EINTR(rc, close(randfd));
return 0; return 0;
#elif defined(JANET_BSD) || defined(MAC_OS_X_VERSION_10_7) #endif
arc4random_buf(out, n);
return 0;
#else #else
(void) n;
(void) out; (void) out;
(void) n;
return -1; return -1;
#endif #endif
} }