mirror of
https://github.com/bellard/quickjs.git
synced 2024-11-22 13:48:11 +08:00
native cosmopolitan build
This commit is contained in:
parent
e80917bad4
commit
9a4379daf6
43
Makefile
43
Makefile
@ -33,12 +33,8 @@ CONFIG_LTO=y
|
|||||||
#CONFIG_WERROR=y
|
#CONFIG_WERROR=y
|
||||||
# force 32 bit build for some utilities
|
# force 32 bit build for some utilities
|
||||||
#CONFIG_M32=y
|
#CONFIG_M32=y
|
||||||
|
# cosmopolitan build (see https://github.com/jart/cosmopolitan)
|
||||||
ifdef CONFIG_DARWIN
|
#CONFIG_COSMO=y
|
||||||
# use clang instead of gcc
|
|
||||||
CONFIG_CLANG=y
|
|
||||||
CONFIG_DEFAULT_AR=y
|
|
||||||
endif
|
|
||||||
|
|
||||||
# installation directory
|
# installation directory
|
||||||
prefix=/usr/local
|
prefix=/usr/local
|
||||||
@ -52,6 +48,12 @@ CONFIG_BIGNUM=y
|
|||||||
|
|
||||||
OBJDIR=.obj
|
OBJDIR=.obj
|
||||||
|
|
||||||
|
ifdef CONFIG_DARWIN
|
||||||
|
# use clang instead of gcc
|
||||||
|
CONFIG_CLANG=y
|
||||||
|
CONFIG_DEFAULT_AR=y
|
||||||
|
endif
|
||||||
|
|
||||||
ifdef CONFIG_WIN32
|
ifdef CONFIG_WIN32
|
||||||
ifdef CONFIG_M32
|
ifdef CONFIG_M32
|
||||||
CROSS_PREFIX=i686-w64-mingw32-
|
CROSS_PREFIX=i686-w64-mingw32-
|
||||||
@ -63,6 +65,7 @@ else
|
|||||||
CROSS_PREFIX=
|
CROSS_PREFIX=
|
||||||
EXE=
|
EXE=
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifdef CONFIG_CLANG
|
ifdef CONFIG_CLANG
|
||||||
HOST_CC=clang
|
HOST_CC=clang
|
||||||
CC=$(CROSS_PREFIX)clang
|
CC=$(CROSS_PREFIX)clang
|
||||||
@ -84,6 +87,14 @@ ifdef CONFIG_CLANG
|
|||||||
AR=$(CROSS_PREFIX)ar
|
AR=$(CROSS_PREFIX)ar
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
else ifdef CONFIG_COSMO
|
||||||
|
CONFIG_LTO=
|
||||||
|
HOST_CC=gcc
|
||||||
|
CC=cosmocc
|
||||||
|
# cosmocc does not correct support -MF
|
||||||
|
CFLAGS=-g -Wall #-MMD -MF $(OBJDIR)/$(@F).d
|
||||||
|
CFLAGS += -Wno-array-bounds -Wno-format-truncation
|
||||||
|
AR=cosmoar
|
||||||
else
|
else
|
||||||
HOST_CC=gcc
|
HOST_CC=gcc
|
||||||
CC=$(CROSS_PREFIX)gcc
|
CC=$(CROSS_PREFIX)gcc
|
||||||
@ -113,7 +124,11 @@ CFLAGS_DEBUG=$(CFLAGS) -O0
|
|||||||
CFLAGS_SMALL=$(CFLAGS) -Os
|
CFLAGS_SMALL=$(CFLAGS) -Os
|
||||||
CFLAGS_OPT=$(CFLAGS) -O2
|
CFLAGS_OPT=$(CFLAGS) -O2
|
||||||
CFLAGS_NOLTO:=$(CFLAGS_OPT)
|
CFLAGS_NOLTO:=$(CFLAGS_OPT)
|
||||||
|
ifdef CONFIG_COSMO
|
||||||
|
LDFLAGS=-s # better to strip by default
|
||||||
|
else
|
||||||
LDFLAGS=-g
|
LDFLAGS=-g
|
||||||
|
endif
|
||||||
ifdef CONFIG_LTO
|
ifdef CONFIG_LTO
|
||||||
CFLAGS_SMALL+=-flto
|
CFLAGS_SMALL+=-flto
|
||||||
CFLAGS_OPT+=-flto
|
CFLAGS_OPT+=-flto
|
||||||
@ -133,6 +148,12 @@ else
|
|||||||
LDEXPORT=-rdynamic
|
LDEXPORT=-rdynamic
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifndef CONFIG_COSMO
|
||||||
|
ifndef CONFIG_DARWIN
|
||||||
|
CONFIG_SHARED_LIBS=y # building shared libraries is supported
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
PROGS=qjs$(EXE) qjsc$(EXE) run-test262
|
PROGS=qjs$(EXE) qjsc$(EXE) run-test262
|
||||||
ifneq ($(CROSS_PREFIX),)
|
ifneq ($(CROSS_PREFIX),)
|
||||||
QJSC_CC=gcc
|
QJSC_CC=gcc
|
||||||
@ -157,10 +178,10 @@ endif
|
|||||||
ifeq ($(CROSS_PREFIX),)
|
ifeq ($(CROSS_PREFIX),)
|
||||||
PROGS+=examples/hello
|
PROGS+=examples/hello
|
||||||
ifndef CONFIG_ASAN
|
ifndef CONFIG_ASAN
|
||||||
PROGS+=examples/hello_module examples/test_fib
|
PROGS+=examples/hello_module
|
||||||
ifndef CONFIG_DARWIN
|
|
||||||
PROGS+=examples/fib.so examples/point.so
|
|
||||||
endif
|
endif
|
||||||
|
ifdef CONFIG_SHARED_LIBS
|
||||||
|
PROGS+=examples/test_fib examples/fib.so examples/point.so
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@ -373,7 +394,7 @@ doc/%.html: doc/%.html.pre
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
# tests
|
# tests
|
||||||
|
|
||||||
ifndef CONFIG_DARWIN
|
ifdef CONFIG_SHARED_LIBS
|
||||||
test: tests/bjson.so examples/point.so
|
test: tests/bjson.so examples/point.so
|
||||||
endif
|
endif
|
||||||
ifdef CONFIG_M32
|
ifdef CONFIG_M32
|
||||||
@ -387,7 +408,7 @@ test: qjs
|
|||||||
./qjs tests/test_loop.js
|
./qjs tests/test_loop.js
|
||||||
./qjs tests/test_std.js
|
./qjs tests/test_std.js
|
||||||
./qjs tests/test_worker.js
|
./qjs tests/test_worker.js
|
||||||
ifndef CONFIG_DARWIN
|
ifdef CONFIG_SHARED_LIBS
|
||||||
ifdef CONFIG_BIGNUM
|
ifdef CONFIG_BIGNUM
|
||||||
./qjs --bignum tests/test_bjson.js
|
./qjs --bignum tests/test_bjson.js
|
||||||
else
|
else
|
||||||
|
21
qjs.c
21
qjs.c
@ -140,19 +140,19 @@ static inline unsigned long long js_trace_malloc_ptr_offset(uint8_t *ptr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* default memory allocation functions with memory limitation */
|
/* default memory allocation functions with memory limitation */
|
||||||
static inline size_t js_trace_malloc_usable_size(void *ptr)
|
static size_t js_trace_malloc_usable_size(const void *ptr)
|
||||||
{
|
{
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
return malloc_size(ptr);
|
return malloc_size(ptr);
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
return _msize(ptr);
|
return _msize((void *)ptr);
|
||||||
#elif defined(EMSCRIPTEN)
|
#elif defined(EMSCRIPTEN)
|
||||||
return 0;
|
return 0;
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
return malloc_usable_size(ptr);
|
return malloc_usable_size((void *)ptr);
|
||||||
#else
|
#else
|
||||||
/* change this to `return 0;` if compilation fails */
|
/* change this to `return 0;` if compilation fails */
|
||||||
return malloc_usable_size(ptr);
|
return malloc_usable_size((void *)ptr);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,18 +264,7 @@ static const JSMallocFunctions trace_mf = {
|
|||||||
js_trace_malloc,
|
js_trace_malloc,
|
||||||
js_trace_free,
|
js_trace_free,
|
||||||
js_trace_realloc,
|
js_trace_realloc,
|
||||||
#if defined(__APPLE__)
|
js_trace_malloc_usable_size,
|
||||||
malloc_size,
|
|
||||||
#elif defined(_WIN32)
|
|
||||||
(size_t (*)(const void *))_msize,
|
|
||||||
#elif defined(EMSCRIPTEN)
|
|
||||||
NULL,
|
|
||||||
#elif defined(__linux__)
|
|
||||||
(size_t (*)(const void *))malloc_usable_size,
|
|
||||||
#else
|
|
||||||
/* change this to `NULL,` if compilation fails */
|
|
||||||
malloc_usable_size,
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define PROG_NAME "qjs"
|
#define PROG_NAME "qjs"
|
||||||
|
21
quickjs.c
21
quickjs.c
@ -1692,19 +1692,19 @@ void JS_SetRuntimeOpaque(JSRuntime *rt, void *opaque)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* default memory allocation functions with memory limitation */
|
/* default memory allocation functions with memory limitation */
|
||||||
static inline size_t js_def_malloc_usable_size(void *ptr)
|
static size_t js_def_malloc_usable_size(const void *ptr)
|
||||||
{
|
{
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
return malloc_size(ptr);
|
return malloc_size(ptr);
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
return _msize(ptr);
|
return _msize((void *)ptr);
|
||||||
#elif defined(EMSCRIPTEN)
|
#elif defined(EMSCRIPTEN)
|
||||||
return 0;
|
return 0;
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
return malloc_usable_size(ptr);
|
return malloc_usable_size((void *)ptr);
|
||||||
#else
|
#else
|
||||||
/* change this to `return 0;` if compilation fails */
|
/* change this to `return 0;` if compilation fails */
|
||||||
return malloc_usable_size(ptr);
|
return malloc_usable_size((void *)ptr);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1768,18 +1768,7 @@ static const JSMallocFunctions def_malloc_funcs = {
|
|||||||
js_def_malloc,
|
js_def_malloc,
|
||||||
js_def_free,
|
js_def_free,
|
||||||
js_def_realloc,
|
js_def_realloc,
|
||||||
#if defined(__APPLE__)
|
js_def_malloc_usable_size,
|
||||||
malloc_size,
|
|
||||||
#elif defined(_WIN32)
|
|
||||||
(size_t (*)(const void *))_msize,
|
|
||||||
#elif defined(EMSCRIPTEN)
|
|
||||||
NULL,
|
|
||||||
#elif defined(__linux__)
|
|
||||||
(size_t (*)(const void *))malloc_usable_size,
|
|
||||||
#else
|
|
||||||
/* change this to `NULL,` if compilation fails */
|
|
||||||
malloc_usable_size,
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
JSRuntime *JS_NewRuntime(void)
|
JSRuntime *JS_NewRuntime(void)
|
||||||
|
Loading…
Reference in New Issue
Block a user