1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-24 09:17:17 +00:00

Initial Mingw support with Makefile.

Also add a macro JANET_MSVC to distinguish between
a windows build (JANET_WINDOWS) and a build with msvc.
This commit is contained in:
bakpakin 2023-01-21 10:37:34 -06:00
parent d8d1de2dcb
commit 93b469885a
10 changed files with 33 additions and 15 deletions

View File

@ -77,6 +77,12 @@ ifeq ($(shell uname -o), Android)
endif
endif
# Mingw
ifeq ($(findstring MINGW,$(UNAME)), MINGW)
CLIBS:=-lws2_32 -lpsapi -lwsock32
LDFLAGS:=
endif
$(shell mkdir -p build/core build/c build/boot)
all: $(JANET_TARGET) $(JANET_LIBRARY) $(JANET_STATIC_LIBRARY) build/janet.h

View File

@ -98,11 +98,11 @@ size_t janet_os_rwlock_size(void) {
}
static int32_t janet_incref(JanetAbstractHead *ab) {
return InterlockedIncrement(&ab->gc.data.refcount);
return InterlockedIncrement((LONG volatile *) &ab->gc.data.refcount);
}
static int32_t janet_decref(JanetAbstractHead *ab) {
return InterlockedDecrement(&ab->gc.data.refcount);
return InterlockedDecrement((LONG volatile *) &ab->gc.data.refcount);
}
void janet_os_mutex_init(JanetOSMutex *mutex) {

View File

@ -2273,7 +2273,7 @@ JanetAsyncStatus ev_machine_read(JanetListenerState *s, JanetAsyncEvent event) {
#ifdef JANET_NET
if (state->mode == JANET_ASYNC_READMODE_RECVFROM) {
state->wbuf.len = (ULONG) chunk_size;
state->wbuf.buf = state->chunk_buf;
state->wbuf.buf = (char *) state->chunk_buf;
status = WSARecvFrom((SOCKET) s->stream->handle, &state->wbuf, 1,
NULL, &state->flags, &state->from, &state->fromlen, &state->overlapped, NULL);
if (status && (WSA_IO_PENDING != WSAGetLastError())) {
@ -2664,15 +2664,15 @@ int janet_make_pipe(JanetHandle handles[2], int mode) {
* so we lift from the windows source code and modify for our own version.
*/
JanetHandle shandle, chandle;
UCHAR PipeNameBuffer[MAX_PATH];
CHAR PipeNameBuffer[MAX_PATH];
SECURITY_ATTRIBUTES saAttr;
memset(&saAttr, 0, sizeof(saAttr));
saAttr.nLength = sizeof(saAttr);
saAttr.bInheritHandle = TRUE;
sprintf(PipeNameBuffer,
"\\\\.\\Pipe\\JanetPipeFile.%08x.%08x",
GetCurrentProcessId(),
InterlockedIncrement(&PipeSerialNumber));
(unsigned int) GetCurrentProcessId(),
(unsigned int) InterlockedIncrement(&PipeSerialNumber));
/* server handle goes to subprocess */
shandle = CreateNamedPipeA(

View File

@ -838,7 +838,6 @@ JANET_CORE_FN(cfun_ffi_signature,
}
/* Add reference items */
size_t old_stack_count = stack_count;
stack_count += 2 * ref_stack_count;
if (stack_count & 0x1) {
stack_count++;

View File

@ -34,9 +34,11 @@
#include <windows.h>
#include <ws2tcpip.h>
#include <mswsock.h>
#ifdef JANET_MSVC
#pragma comment (lib, "Ws2_32.lib")
#pragma comment (lib, "Mswsock.lib")
#pragma comment (lib, "Advapi32.lib")
#endif
#else
#include <arpa/inet.h>
#include <unistd.h>
@ -173,7 +175,6 @@ JanetAsyncStatus net_machine_accept(JanetListenerState *s, JanetAsyncEvent event
JANET_NO_RETURN static void janet_sched_accept(JanetStream *stream, JanetFunction *fun) {
Janet err;
SOCKET lsock = (SOCKET) stream->handle;
JanetListenerState *s = janet_listen(stream, net_machine_accept, JANET_ASYNC_LISTEN_READ, sizeof(NetStateAccept), NULL);
NetStateAccept *state = (NetStateAccept *)s;
memset(&state->overlapped, 0, sizeof(WSAOVERLAPPED));
@ -706,7 +707,7 @@ JANET_CORE_FN(cfun_net_getsockname,
if (getsockname((JSock)js->handle, (struct sockaddr *) &ss, &slen)) {
janet_panicf("Failed to get localname on %v: %V", argv[0], janet_ev_lasterr());
}
janet_assert(slen <= sizeof(ss), "socket address truncated");
janet_assert(slen <= (socklen_t) sizeof(ss), "socket address truncated");
return janet_so_getname(&ss);
}
@ -722,7 +723,7 @@ JANET_CORE_FN(cfun_net_getpeername,
if (getpeername((JSock)js->handle, (struct sockaddr *)&ss, &slen)) {
janet_panicf("Failed to get peername on %v: %V", argv[0], janet_ev_lasterr());
}
janet_assert(slen <= sizeof(ss), "socket address truncated");
janet_assert(slen <= (socklen_t) sizeof(ss), "socket address truncated");
return janet_so_getname(&ss);
}

View File

@ -445,7 +445,7 @@ typedef struct {
static JanetEVGenericMessage janet_proc_wait_subr(JanetEVGenericMessage args) {
JanetProc *proc = (JanetProc *) args.argp;
WaitForSingleObject(proc->pHandle, INFINITE);
GetExitCodeProcess(proc->pHandle, &args.tag);
GetExitCodeProcess(proc->pHandle, (LPDWORD) &args.tag);
return args;
}
@ -902,9 +902,6 @@ static Janet os_execute_impl(int32_t argc, Janet *argv, int is_spawn) {
janet_panic("failed to create pipes");
}
/* Result */
int status = 0;
#ifdef JANET_WINDOWS
HANDLE pHandle, tHandle;
@ -983,6 +980,9 @@ static Janet os_execute_impl(int32_t argc, Janet *argv, int is_spawn) {
#else
/* Result */
int status = 0;
const char **child_argv = janet_smalloc(sizeof(char *) * ((size_t) exargs.len + 1));
for (int32_t i = 0; i < exargs.len; i++)
child_argv[i] = janet_getcstring(exargs.items, i);
@ -1769,9 +1769,11 @@ static Janet os_stat_changed(jstat_t *st) {
}
#ifdef JANET_WINDOWS
static Janet os_stat_blocks(jstat_t *st) {
(void) st;
return janet_wrap_number(0);
}
static Janet os_stat_blocksize(jstat_t *st) {
(void) st;
return janet_wrap_number(0);
}
#else
@ -2047,6 +2049,7 @@ JANET_CORE_FN(os_open,
uint32_t stream_flags = 0;
JanetHandle fd;
#ifdef JANET_WINDOWS
(void) mode;
DWORD desiredAccess = 0;
DWORD shareMode = 0;
DWORD creationDisp = 0;

View File

@ -39,9 +39,11 @@
#ifdef JANET_WINDOWS
#ifdef JANET_DYNAMIC_MODULES
#include <psapi.h>
#ifdef JANET_MSVC
#pragma comment (lib, "Psapi.lib")
#endif
#endif
#endif
#ifdef JANET_APPLE
#include <AvailabilityMacros.h>
@ -863,7 +865,7 @@ int janet_cryptorand(uint8_t *out, size_t n) {
unsigned int v;
if (rand_s(&v))
return -1;
for (int32_t j = 0; (j < sizeof(unsigned int)) && (i + j < n); j++) {
for (int32_t j = 0; (j < (int32_t) sizeof(unsigned int)) && (i + j < n); j++) {
out[i + j] = v & 0xff;
v = v >> 8;
}

View File

@ -92,6 +92,11 @@ extern "C" {
#define JANET_WINDOWS 1
#endif
/* Check if compiling with MSVC - else assume a GCC-like compiler by default */
#ifdef _MSC_VER
#define JANET_MSVC
#endif
/* Check 64-bit vs 32-bit */
#if ((defined(__x86_64__) || defined(_M_X64)) \
&& (defined(JANET_POSIX) || defined(JANET_WINDOWS))) \

View File

@ -296,6 +296,7 @@ static char *sdup(const char *s) {
return memcpy(mem, s, len);
}
#ifndef _WIN32
static int curpos(void) {
char buf[32];
int cols, rows;
@ -311,6 +312,7 @@ static int curpos(void) {
if (sscanf(buf + 2, "%d;%d", &rows, &cols) != 2) return -1;
return cols;
}
#endif
static int getcols(void) {
#ifdef _WIN32

0
tools/format.sh Executable file → Normal file
View File