diff --git a/INSTALL b/INSTALL index a4ba6826f..261fffb44 100644 --- a/INSTALL +++ b/INSTALL @@ -208,3 +208,63 @@ imoprtant to specify a different size. For example: #+begin_src shell-script emcc program.c -sSTACK_SIZE=1048576 lib/*.a -I./include -o program.o #+end_src + +* Build using Cosmopolitan toolchain (experimental) + +Binaries built with cosmopolitan toolchain can be executed on numerous platforms +without changes. An inititial ECL port has been completed. + +1. Download cosmopolitan toolchain and activate it + +Instructions for downloading the toolchain are available in its [[https://github.com/jart/cosmopolitan/blob/master/README.md ][repository]]. +For example: + +#+begin_src sh + mkdir cosmocc + pushd cosmocc + curl -o https://cosmo.zip/pub/cosmocc/cosmocc.zip + unzip *zip + bin/make --version # sanity test + export PATH="`pwd`/bin:${PATH}" + export CC=x86_64-unknown-cosmo-cc + export CXX=x86_64-unknown-cosmo-c++ + popd +#+end_src + +2. Build ECL + +#+begin_src sh + ./configure --disable-shared --prefix=/tmp/cosmo-cl + make -j15 + make install + # make check +#+end_src + +- The platform is reported in *FEATURES* as :COSMO and as :LINUX +- make check will fail because libc segfaults when using fenv.h + +This platform is not upstreamed yet in libgc, so it may be necessary to add the +following code to the file gcconfig.h: + +#+begin_src c +# if defined(__COSMOPOLITAN__) +# if defined(__x86_64__) +# define mach_type_known +# define X86_64 +# define LINUX // optional? +# elif defined(__aarch64__) +# define mach_type_known +# define AARCH64 +# define LINUX // optional? +# endif +# endif +#+end_src + +For details see: https://github.com/jart/cosmopolitan/issues/939. + +Cosmopolitan condition variables can't be used with mutexes that are not +initialized as PTHREAD_MUTEX_NORMAL. That means that recursive locks and +deterministic deadlock detection are not supported on this platform. + +Moreover floating point exception handling is not working and it is libc issue +that manifests itself with segfaults. diff --git a/contrib/asdf/asdf.lisp b/contrib/asdf/asdf.lisp index 1a9572baf..ec83592fd 100644 --- a/contrib/asdf/asdf.lisp +++ b/contrib/asdf/asdf.lisp @@ -1,5 +1,5 @@ ;;; -*- mode: Lisp; Base: 10 ; Syntax: ANSI-Common-Lisp ; buffer-read-only: t; -*- -;;; This is ASDF 3.1.8.8: Another System Definition Facility. +;;; This is ASDF 3.1.8.9: Another System Definition Facility. ;;; ;;; Feedback, bug reports, and patches are all welcome: ;;; please mail to . @@ -1732,7 +1732,7 @@ keywords explicitly." (defun os-unix-p () "Is the underlying operating system some Unix variant?" - (or (featurep '(:or :unix :cygwin)) (os-macosx-p))) + (or (featurep '(:or :unix :cygwin :haiku :linux)) (os-macosx-p))) (defun os-windows-p () "Is the underlying operating system Microsoft Windows?" @@ -7274,7 +7274,7 @@ previously-loaded version of ASDF." ;; "3.4.5.67" would be a development version in the official branch, on top of 3.4.5. ;; "3.4.5.0.8" would be your eighth local modification of official release 3.4.5 ;; "3.4.5.67.8" would be your eighth local modification of development version 3.4.5.67 - (asdf-version "3.1.8.8") + (asdf-version "3.1.8.9") (existing-version (asdf-version))) (setf *asdf-version* asdf-version) (when (and existing-version (not (equal asdf-version existing-version))) diff --git a/src/bdwgc/include/private/gcconfig.h b/src/bdwgc/include/private/gcconfig.h index f173d5a13..559c540e2 100644 --- a/src/bdwgc/include/private/gcconfig.h +++ b/src/bdwgc/include/private/gcconfig.h @@ -712,6 +712,18 @@ EXTERN_C_BEGIN # define mach_type_known # endif +# if defined(__COSMOPOLITAN__) +# if defined(__x86_64__) +# define mach_type_known +# define X86_64 +# define LINUX // optional? +# elif defined(__aarch64__) +# define mach_type_known +# define AARCH64 +# define LINUX // optional? +# endif +# endif + /* Feel free to add more clauses here */ /* Or manually define the machine type here. A machine type is */ diff --git a/src/c/ecl_features.h b/src/c/ecl_features.h index 6f480203e..2551387cd 100644 --- a/src/c/ecl_features.h +++ b/src/c/ecl_features.h @@ -62,6 +62,9 @@ ecl_def_string_array(feature_names,static,const) = { #if defined(ECL_MS_WINDOWS_HOST) ecl_def_string_array_elt("WINDOWS"), #endif +#if defined(__COSMOPOLITAN__) + ecl_def_string_array_elt("COSMO"), +#endif #ifdef ECL_CMU_FORMAT ecl_def_string_array_elt("CMU-FORMAT"), #endif diff --git a/src/c/threads/process.d b/src/c/threads/process.d index 96ef852b5..215f694ba 100755 --- a/src/c/threads/process.d +++ b/src/c/threads/process.d @@ -724,9 +724,8 @@ mp_process_run_function_wait(cl_narg narg, ...) process = cl_apply(2, @'mp::process-run-function', cl_grab_rest_args(args)); if (!Null(process)) { - ecl_def_ct_single_float(wait, 0.001, static, const); while (process->process.phase < ECL_PROCESS_ACTIVE) { - cl_sleep(wait); + ecl_musleep(0.001); } } ecl_va_end(args); diff --git a/src/h/impl/math_fenv.h b/src/h/impl/math_fenv.h index b815d6e09..18962cbb0 100644 --- a/src/h/impl/math_fenv.h +++ b/src/h/impl/math_fenv.h @@ -46,7 +46,7 @@ # include #endif -#ifdef HAVE_FENV_H +#if defined(HAVE_FENV_H) && !defined(__COSMOPOLITAN__) # define ECL_WITHOUT_FPE_BEGIN do { fenv_t env; feholdexcept(&env); # define ECL_WITHOUT_FPE_END fesetenv(&env); } while (0) # if !defined(FE_DIVBYZERO) diff --git a/src/h/internal.h b/src/h/internal.h index 064e0e079..fe3fb5a1b 100755 --- a/src/h/internal.h +++ b/src/h/internal.h @@ -351,12 +351,15 @@ extern enum ecl_ffi_tag ecl_foreign_type_code(cl_object type); /* file.d */ /* Windows does not have this flag (POSIX thing) */ -#ifndef O_CLOEXEC -#define O_CLOEXEC 0 -#endif -#ifndef O_NONBLOCK -#define O_NONBLOCK 0 +#ifndef __COSMOPOLITAN__ +# ifndef O_CLOEXEC +# define O_CLOEXEC 0 +# endif +# ifndef O_NONBLOCK +# define O_NONBLOCK 0 +# endif #endif + /* Windows needs to be told explicitely to open files in binary mode */ #ifndef O_BINARY #define O_BINARY 0 @@ -691,11 +694,10 @@ extern void ecl_interrupt_process(cl_object process, cl_object function); /* Some old BSD systems don't have WCONTINUED / WIFCONTINUED */ -#ifndef ECL_MS_WINDOWS_HOST +#if !defined(ECL_MS_WINDOWS_HOST) && !defined(__COSMOPOLITAN__) # ifndef WCONTINUED # define WCONTINUED 0 # endif - # ifndef WIFCONTINUED # define WIFCONTINUED(x) 0 # endif diff --git a/src/h/threads.h b/src/h/threads.h index a7c2eb2cb..ba6bb38c9 100644 --- a/src/h/threads.h +++ b/src/h/threads.h @@ -54,11 +54,15 @@ ecl_mutex_init(ecl_mutex_t *mutex, bool recursive) { pthread_mutexattr_t mutexattr[1]; pthread_mutexattr_init(mutexattr); +#ifdef __COSMOPOLITAN__ + pthread_mutexattr_settype(mutexattr, PTHREAD_MUTEX_NORMAL); +#else if (recursive) { pthread_mutexattr_settype(mutexattr, PTHREAD_MUTEX_RECURSIVE); } else { pthread_mutexattr_settype(mutexattr, PTHREAD_MUTEX_ERRORCHECK); } +#endif pthread_mutex_init(mutex, mutexattr); }