diff --git a/.github/workflows/ci-idris2.yml b/.github/workflows/ci-idris2.yml index 9ee8ec320..1591d76f3 100644 --- a/.github/workflows/ci-idris2.yml +++ b/.github/workflows/ci-idris2.yml @@ -164,6 +164,11 @@ jobs: run: c:\msys64\usr\bin\bash -l -c "cd $env:PWD && make bootstrap-test" - name: Install run: c:\msys64\usr\bin\bash -l -c "cd $env:PWD && make install" + - name: Artifact Idris2 from chez + uses: actions/upload-artifact@v2 + with: + name: windows-installed-bootstrapped-idris2-chez + path: ${{ env.IDRIS_PREFIX }} nix-bootstrap-chez: needs: quick-check @@ -314,6 +319,58 @@ jobs: name: idris2-nightly-chez path: ~/.idris2/ + windows-self-host-racket: + needs: windows-bootstrap-chez + runs-on: windows-latest + env: + IDRIS2_CG: racket + MSYSTEM: MINGW64 + MSYS2_PATH_TYPE: inherit + CC: gcc + RACKET_RACO: raco + steps: + - name: Init + run: | + git config --global core.autocrlf false + echo "PWD=$(c:\msys64\usr\bin\cygpath -u $(pwd))" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + - name: Checkout + uses: actions/checkout@v2 + - name: Get Chez Scheme + run: | + git clone --depth 1 https://github.com/cisco/ChezScheme + c:\msys64\usr\bin\bash -l -c "pacman -S --noconfirm tar make" + echo "PWD=$(c:\msys64\usr\bin\cygpath -u $(pwd))" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + - name: Configure and Build Chez Scheme + run: | + c:\msys64\usr\bin\bash -l -c "cd $env:PWD && cd ChezScheme && ./configure --threads && make" + - name: Set Path + run: | + $chez="$(pwd)\ChezScheme\ta6nt\bin\ta6nt" + $idris="$(pwd)\.idris2" + echo "$chez" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + echo "$idris\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + echo "IDRIS_PREFIX=$idris" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + echo "PREFIX=$(c:\msys64\usr\bin\cygpath -u $idris)" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + - name: Download Idris2 Artifact + uses: actions/download-artifact@v2 + with: + name: windows-installed-bootstrapped-idris2-chez + path: ${{ env.IDRIS_PREFIX }} + - name: Install build dependencies + uses: Bogdanp/setup-racket@v1.4 + with: + variant: 'CS' + version: 'stable' + distribution: 'full' + - name: Self host + run: | + c:\msys64\usr\bin\bash -l -c "cd $env:PWD && make" + # TODO: fix the broken tests! + # - name: Test + # run: c:\msys64\usr\bin\bash -l -c "cd $env:PWD && make test" + - name: Install + run: c:\msys64\usr\bin\bash -l -c "cd $env:PWD && make install" + ###################################################################### # Ubuntu API ###################################################################### diff --git a/bootstrap-stage2.sh b/bootstrap-stage2.sh index 735e16e2d..26e3c9e02 100755 --- a/bootstrap-stage2.sh +++ b/bootstrap-stage2.sh @@ -2,14 +2,14 @@ set -e # exit on any error -PREFIX=$PWD/bootstrap-build +BOOTSTRAP_PREFIX=$PWD/bootstrap-build if [ "$OS" = "windows" ]; then # IDRIS_PREFIX is only used to build IDRIS2_BOOT_PATH - IDRIS_PREFIX=$(cygpath -m "$PREFIX") + IDRIS_PREFIX=$(cygpath -m "$BOOTSTRAP_PREFIX") SEP=";" else - IDRIS_PREFIX=$PREFIX + IDRIS_PREFIX=$BOOTSTRAP_PREFIX SEP=":" fi @@ -18,18 +18,18 @@ IDRIS2_CG="${IDRIS2_CG-"chez"}" BOOT_PATH_BASE=$IDRIS_PREFIX/idris2-$IDRIS2_VERSION IDRIS2_BOOT_PATH="$BOOT_PATH_BASE/prelude$SEP $BOOT_PATH_BASE/base$SEP $BOOT_PATH_BASE/contrib$SEP $BOOT_PATH_BASE/network $BOOT_PATH_BASE/test" -# PREFIX must be the "clean" build root, without cygpath -m +# BOOTSTRAP_PREFIX must be the "clean" build root, without cygpath -m # Otherwise, we get 'git: Bad address' -echo "$PREFIX" -DYLIB_PATH="$PREFIX/lib" +echo "$BOOTSTRAP_PREFIX" +DYLIB_PATH="$BOOTSTRAP_PREFIX/lib" $MAKE libs IDRIS2_CG="$IDRIS2_CG" LD_LIBRARY_PATH="$DYLIB_PATH" \ - PREFIX="$PREFIX" SCHEME="$SCHEME" + PREFIX="$BOOTSTRAP_PREFIX" SCHEME="$SCHEME" $MAKE install IDRIS2_CG="$IDRIS2_CG" LD_LIBRARY_PATH="$DYLIB_PATH" \ - PREFIX="$PREFIX" SCHEME="$SCHEME" + PREFIX="$BOOTSTRAP_PREFIX" SCHEME="$SCHEME" # Now rebuild everything properly -$MAKE clean-libs IDRIS2_BOOT="$PREFIX/bin/idris2" -$MAKE all IDRIS2_BOOT="$PREFIX/bin/idris2" IDRIS2_CG="$IDRIS2_CG" \ +$MAKE clean-libs IDRIS2_BOOT="$BOOTSTRAP_PREFIX/bin/idris2" +$MAKE all IDRIS2_BOOT="$BOOTSTRAP_PREFIX/bin/idris2" IDRIS2_CG="$IDRIS2_CG" \ IDRIS2_PATH="$IDRIS2_BOOT_PATH" LD_LIBRARY_PATH="$DYLIB_PATH" \ SCHEME="$SCHEME" diff --git a/bootstrap/idris2-boot.sh b/bootstrap/idris2-boot.sh index f05a9b3af..f57f7a919 100755 --- a/bootstrap/idris2-boot.sh +++ b/bootstrap/idris2-boot.sh @@ -7,14 +7,15 @@ if [ -z "$SCHEME" ]; then exit 1 fi -if [ "$(uname)" = Darwin ]; then +if [ "$OS" = windows ] || [ "$OS" = Windows_NT ]; then + DIR=$(dirname "$(readlink -f -- "$0" || cygpath -a -- "$0")") + PATH=$DIR/idris2_app:$PATH +elif [ "$(uname)" = Darwin ]; then DIR=$(zsh -c 'printf %s "$0:A:h"' "$0") else DIR=$(dirname "$(readlink -f -- "$0")") fi -LD_LIBRARY_PATH="$DIR/idris2_app":$LD_LIBRARY_PATH -PATH="$DIR/idris2_app":$PATH -export LD_LIBRARY_PATH PATH +export LD_LIBRARY_PATH="$DIR/idris2_app:$LD_LIBRARY_PATH" ${SCHEME} --script "$DIR/idris2_app/idris2-boot.so" "$@" diff --git a/bootstrap/idris2-rktboot.sh b/bootstrap/idris2-rktboot.sh index 10e1dde1a..a4b3e7072 100755 --- a/bootstrap/idris2-rktboot.sh +++ b/bootstrap/idris2-rktboot.sh @@ -2,14 +2,15 @@ set -e # exit on any error -if [ "$(uname)" = Darwin ]; then +if [ "$OS" = windows ] || [ "$OS" = Windows_NT ]; then + DIR=$(dirname "$(readlink -f -- "$0" || cygpath -a -- "$0")") + PATH=$DIR/idris2_app:$PATH +elif [ "$(uname)" = Darwin ]; then DIR=$(zsh -c 'printf %s "$0:A:h"' "$0") else DIR=$(dirname "$(readlink -f -- "$0")") fi -LD_LIBRARY_PATH="$DIR/idris2_app":$LD_LIBRARY_PATH -PATH="$DIR/idris2_app":$PATH -export LD_LIBRARY_PATH PATH +export LD_LIBRARY_PATH="$DIR/idris2_app:$LD_LIBRARY_PATH" "$DIR/idris2_app/idris2-boot" "$@" diff --git a/config.mk b/config.mk index 9a0d20313..5dfac7534 100644 --- a/config.mk +++ b/config.mk @@ -27,24 +27,27 @@ else ifneq (,$(findstring windows, $(MACHINE))) else ifneq (,$(findstring darwin, $(MACHINE))) OS := darwin SHLIB_SUFFIX := .dylib - CFLAGS += -fPIC else ifneq (, $(findstring bsd, $(MACHINE))) OS := bsd SHLIB_SUFFIX := .so - CFLAGS += -fPIC else OS := linux SHLIB_SUFFIX := .so - CFLAGS += -fPIC endif -export OS + +ifneq ($(OS),windows) + CFLAGS += -fPIC +else ifneq (, $(findstring NT-6.1,$(shell uname))) + OLD_WIN = 1 +endif ifeq ($(OS),bsd) MAKE := gmake else MAKE := make endif -export MAKE + +export OS MAKE OLD_WIN # Add a custom.mk file to override any of the configurations -include custom.mk diff --git a/libs/base/System/File.idr b/libs/base/System/File.idr index 9a7800098..45da0a074 100644 --- a/libs/base/System/File.idr +++ b/libs/base/System/File.idr @@ -95,7 +95,7 @@ prim__stdout : FilePtr "node:lambda:x=>({fd:2, buffer: Buffer.alloc(0), name:'', eof: false})" prim__stderr : FilePtr -%foreign "C:chmod, libc 6, sys/stat.h" +%foreign support "idris2_chmod" "node:support:chmod,support_system_file" prim__chmod : String -> Int -> PrimIO Int diff --git a/libs/network/Network/FFI.idr b/libs/network/Network/FFI.idr index 04fa76553..38d5c4b5e 100644 --- a/libs/network/Network/FFI.idr +++ b/libs/network/Network/FFI.idr @@ -5,23 +5,16 @@ module Network.FFI import Network.Socket.Data --- From sys/socket.h - -%foreign "C:close, libc 6" -export -prim__socket_close : (sockdes : SocketDescriptor) -> PrimIO Int - -%foreign "C:listen, libc 6" -export -prim__socket_listen : (sockfd : SocketDescriptor) -> (backlog : Int) -> PrimIO Int - - -- From idris_net.h %foreign "C:idrnet_socket, libidris2_support, idris_net.h" export prim__idrnet_socket : (domain, type, protocol : Int) -> PrimIO Int +%foreign "C:idrnet_close, libidris2_support, idris_net.h" +export +prim__idrnet_close : (sockdes : SocketDescriptor) -> PrimIO Int + %foreign "C:idrnet_bind, libidris2_support, idris_net.h" export prim__idrnet_bind : (sockfd : SocketDescriptor) -> (family, socket_type : Int) -> @@ -32,6 +25,14 @@ export prim__idrnet_connect : (sockfd : SocketDescriptor) -> (family, socket_type : Int) -> (host : String) -> (port : Port) -> PrimIO Int +%foreign "C:idrnet_listen, libidris2_support, idris_net.h" +export +prim__idrnet_listen : (sockfd : SocketDescriptor) -> (backlog : Int) -> PrimIO Int + +%foreign "C:idrnet_fdopen, libidris2_support, idris_net.h" +export +prim__idrnet_fdopen : Int -> String -> PrimIO AnyPtr + %foreign "C:idrnet_sockaddr_family, libidris2_support, idris_net.h" export prim__idrnet_sockaddr_family : (sockaddr : AnyPtr) -> PrimIO Int diff --git a/libs/network/Network/Socket.idr b/libs/network/Network/Socket.idr index 3eb8a194c..30dee0353 100644 --- a/libs/network/Network/Socket.idr +++ b/libs/network/Network/Socket.idr @@ -29,7 +29,7 @@ socket sf st pn = do ||| Close a socket export close : HasIO io => Socket -> io () -close sock = do _ <- primIO $ prim__socket_close $ descriptor sock +close sock = do _ <- primIO $ prim__idrnet_close $ descriptor sock pure () ||| Binds a socket to the given socket address and port. @@ -78,7 +78,7 @@ connect sock addr port = do export listen : HasIO io => (sock : Socket) -> io Int listen sock = do - listen_res <- primIO $ prim__socket_listen (descriptor sock) BACKLOG + listen_res <- primIO $ prim__idrnet_listen (descriptor sock) BACKLOG if listen_res == (-1) then getErrno else pure 0 diff --git a/src/Compiler/Scheme/Chez.idr b/src/Compiler/Scheme/Chez.idr index 63fd8ec7a..edd4ccc3b 100644 --- a/src/Compiler/Scheme/Chez.idr +++ b/src/Compiler/Scheme/Chez.idr @@ -94,8 +94,7 @@ schHeader chez libs whole " [(i3fb ti3fb a6fb ta6fb) #f]\n" ++ " [(i3le ti3le a6le ta6le) (load-shared-object \"libc.so.6\")]\n" ++ " [(i3osx ti3osx a6osx ta6osx) (load-shared-object \"libc.dylib\")]\n" ++ - " [(i3nt ti3nt a6nt ta6nt) (load-shared-object \"msvcrt.dll\")" ++ - " (load-shared-object \"ws2_32.dll\")]\n" ++ + " [(i3nt ti3nt a6nt ta6nt) (load-shared-object \"msvcrt.dll\")]\n" ++ " [else (load-shared-object \"libc.so\")])\n\n" ++ showSep "\n" (map (\x => "(load-shared-object \"" ++ escapeStringChez x ++ "\")") libs) ++ "\n\n" ++ if whole @@ -402,7 +401,7 @@ startChezPreamble = unlines startChez : String -> String -> String startChez appdir target = startChezPreamble ++ unlines - [ "export LD_LIBRARY_PATH=\"$DIR/" ++ appdir ++ "\":$LD_LIBRARY_PATH" + [ "export LD_LIBRARY_PATH=\"$DIR/" ++ appdir ++ ":$LD_LIBRARY_PATH\"" , "export IDRIS2_INC_SRC=\"$DIR/" ++ appdir ++ "\"" , "\"$DIR/" ++ target ++ "\" \"$@\"" ] @@ -411,9 +410,9 @@ startChezCmd : String -> String -> String -> String -> String startChezCmd chez appdir target progType = unlines [ "@echo off" , "set APPDIR=%~dp0" - , "set PATH=%APPDIR%\\" ++ appdir ++ ";%PATH%" - , "set IDRIS2_INC_SRC=%APPDIR%\\" ++ appdir - , "\"" ++ chez ++ "\" " ++ progType ++ " \"%APPDIR%/" ++ target ++ "\" %*" + , "set PATH=%APPDIR%" ++ appdir ++ ";%PATH%" + , "set IDRIS2_INC_SRC=%APPDIR%" ++ appdir + , "\"" ++ chez ++ "\" " ++ progType ++ " \"%APPDIR%" ++ target ++ "\" %*" ] startChezWinSh : String -> String -> String -> String -> String @@ -423,11 +422,10 @@ startChezWinSh chez appdir target progType = unlines , "" , "set -e # exit on any error" , "" - , "DIR=$(dirname \"$(readlink -f -- \"$0\")\")" - , "CHEZ=$(cygpath \"" ++ chez ++"\")" - , "export PATH=\"$DIR/" ++ appdir ++ "\":$PATH" + , "DIR=$(dirname \"$(readlink -f -- \"$0\" || cygpath -a -- \"$0\")\")" + , "PATH=\"$DIR/" ++ appdir ++ ":$PATH\"" , "export IDRIS2_INC_SRC=\"$DIR/" ++ appdir ++ "\"" - , "\"$CHEZ\" " ++ progType ++ " \"$DIR/" ++ target ++ "\" \"$@\"" + , "\"" ++ chez ++ "\" " ++ progType ++ " \"$DIR/" ++ target ++ "\" \"$@\"" ] ||| Compile a TT expression to Chez Scheme diff --git a/src/Compiler/Scheme/ChezSep.idr b/src/Compiler/Scheme/ChezSep.idr index 5c20a5100..ec872936e 100644 --- a/src/Compiler/Scheme/ChezSep.idr +++ b/src/Compiler/Scheme/ChezSep.idr @@ -58,7 +58,7 @@ schFooter = "(collect 4)\n(blodwen-run-finalisers)\n" startChez : String -> String -> String -> String startChez chez appDirSh targetSh = Chez.startChezPreamble ++ unlines - [ "export LD_LIBRARY_PATH=\"$DIR/" ++ appDirSh ++ "\":$LD_LIBRARY_PATH" + [ "export LD_LIBRARY_PATH=\"$DIR/" ++ appDirSh ++ ":$LD_LIBRARY_PATH\"" , "\"" ++ chez ++ "\" -q " ++ "--libdirs \"$DIR/" ++ appDirSh ++ "\" " ++ "--program \"$DIR/" ++ targetSh ++ "\" " @@ -69,10 +69,10 @@ startChezCmd : String -> String -> String -> String startChezCmd chez appDirSh targetSh = unlines [ "@echo off" , "set APPDIR=%~dp0" - , "set PATH=%APPDIR%\\" ++ appDirSh ++ ";%PATH%" + , "set PATH=%APPDIR%" ++ appDirSh ++ ";%PATH%" , "\"" ++ chez ++ "\" -q " - ++ "--libdirs \"%APPDIR%/" ++ appDirSh ++ "\" " - ++ "--program \"%APPDIR%/" ++ targetSh ++ "\" " + ++ "--libdirs \"%APPDIR%" ++ appDirSh ++ "\" " + ++ "--program \"%APPDIR%" ++ targetSh ++ "\" " ++ "%*" ] @@ -83,11 +83,10 @@ startChezWinSh chez appDirSh targetSh = unlines , "" , "set -e # exit on any error" , "" - , "DIR=$(dirname \"$(readlink -f -- \"$0\")\")" - , "CHEZ=$(cygpath \"" ++ chez ++"\")" - , "export PATH=\"$DIR/" ++ appDirSh ++ "\":$PATH" - , "\"$CHEZ\" --program \"$DIR/" ++ targetSh ++ "\" \"$@\"" - , "\"$CHEZ\" -q " + , "DIR=$(dirname \"$(readlink -f -- \"$0\" || cygpath -a -- \"$0\")\")" + , "PATH=\"$DIR/" ++ appDirSh ++ ":$PATH\"" + , "\"" ++ chez ++ "\" --program \"$DIR/" ++ targetSh ++ "\" \"$@\"" + , "\"" ++ chez ++ "\" -q " ++ "--libdirs \"$DIR/" ++ appDirSh ++ "\" " ++ "--program \"$DIR/" ++ targetSh ++ "\" " ++ "\"$@\"" diff --git a/src/Compiler/Scheme/Racket.idr b/src/Compiler/Scheme/Racket.idr index 1cf26704d..4a52a7e3f 100644 --- a/src/Compiler/Scheme/Racket.idr +++ b/src/Compiler/Scheme/Racket.idr @@ -54,7 +54,7 @@ schHeader prof libs "(require srfi/19)\n" ++ -- for file handling and data "(require ffi/unsafe ffi/unsafe/define)\n" ++ -- for calling C (if prof then "(require profile)\n" else "") ++ - "(require racket/flonum)" ++ -- for float-typed transcendental functions + "(require racket/flonum)\n" ++ -- for float-typed transcendental functions libs ++ "(let ()\n" @@ -149,7 +149,7 @@ cftySpec fc t = throw (GenericMsg fc ("Can't pass argument of type " ++ show t + " to foreign function")) loadlib : String -> String -> String -loadlib "libc" _ = "(define-ffi-definer define-libc (ffi-lib #f))" +loadlib "libc" _ = "(define-ffi-definer define-libc (ffi-lib #f))\n" loadlib libn ver = "(define-ffi-definer define-" ++ libn ++ " (ffi-lib \"" ++ libn ++ "\" " ++ ver ++ "))\n" @@ -342,7 +342,7 @@ startRacket racket appdir target = unlines , " DIR=$(dirname \"$(readlink -f -- \"$0\")\")" , "fi" , "" - , "export LD_LIBRARY_PATH=\"$DIR/" ++ appdir ++ "\":$LD_LIBRARY_PATH" + , "export LD_LIBRARY_PATH=\"$DIR/" ++ appdir ++ ":$LD_LIBRARY_PATH\"" , racket ++ "\"$DIR/" ++ target ++ "\" \"$@\"" ] @@ -350,8 +350,8 @@ startRacketCmd : String -> String -> String -> String startRacketCmd racket appdir target = unlines [ "@echo off" , "set APPDIR=%~dp0" - , "set PATH=%APPDIR%\\" ++ appdir ++ ";%PATH%" - , racket ++ "\"" ++ target ++ "\" %*" + , "set PATH=%APPDIR%" ++ appdir ++ ";%PATH%" + , racket ++ "\"%APPDIR%" ++ target ++ "\" %*" ] startRacketWinSh : String -> String -> String -> String @@ -361,9 +361,9 @@ startRacketWinSh racket appdir target = unlines , "" , "set -e # exit on any error" , "" - , "DIR=$(dirname \"$(readlink -f -- \"$0\")\")" - , "export PATH=\"$DIR/" ++ appdir ++ "\":$PATH" - , racket ++ "\"" ++ target ++ "\" \"$@\"" + , "DIR=$(dirname \"$(readlink -f -- \"$0\" || cygpath -a -- \"$0\")\")" + , "PATH=\"$DIR/" ++ appdir ++ ":$PATH\"" + , racket ++ "\"$DIR/" ++ target ++ "\" \"$@\"" ] compileToRKT : Ref Ctxt Defs -> diff --git a/src/Idris/IDEMode/REPL.idr b/src/Idris/IDEMode/REPL.idr index aaf0d777e..e4ca12e40 100644 --- a/src/Idris/IDEMode/REPL.idr +++ b/src/Idris/IDEMode/REPL.idr @@ -55,13 +55,14 @@ import Network.Socket.Data %default covering -%foreign "C:fdopen,libc 6" -prim__fdopen : Int -> String -> PrimIO AnyPtr +||| TODO: use the version in `Network.FFI` in network after the next release. +%foreign "C:idrnet_fdopen, libidris2_support, idris_net.h" +prim__idrnet_fdopen : Int -> String -> PrimIO AnyPtr export socketToFile : Socket -> IO (Either String File) socketToFile (MkSocket f _ _ _) = do - file <- FHandle <$> primIO (prim__fdopen f "r+") + file <- FHandle <$> primIO (prim__idrnet_fdopen f "r+") if !(fileError file) then pure (Left "Failed to fdopen socket file descriptor") else pure (Right file) diff --git a/support/c/Makefile b/support/c/Makefile index f7831faaa..ad5fdf35c 100644 --- a/support/c/Makefile +++ b/support/c/Makefile @@ -5,19 +5,21 @@ TARGET = libidris2_support LIBTARGET = $(TARGET).a DYLIBTARGET = $(TARGET)$(SHLIB_SUFFIX) -CFLAGS += -O2 - -SRCS = $(wildcard *.c) -ifeq ($(OS), windows) - SRCS += windows/win_utils.c windows/win_hack.c - LDFLAGS += -lws2_32 -ifeq ($(OLD_WIN), 1) - CFLAGS += -D_OLD_WIN -endif -endif +SRCS := $(wildcard *.c) OBJS = $(SRCS:.c=.o) DEPS = $(OBJS:.o=.d) +CFLAGS += -O2 + +ifeq ($(OS), windows) + SRCS += windows/win_utils.c windows/win_hack.c + CPPFLAGS += -DWIN32_LEAN_AND_MEAN + LDFLAGS += -lws2_32 +ifeq ($(OLD_WIN), 1) + CPPFLAGS += -D_OLD_WIN +endif +endif + all: build diff --git a/support/c/idris_file.c b/support/c/idris_file.c index 86b96fce0..62f23ef64 100644 --- a/support/c/idris_file.c +++ b/support/c/idris_file.c @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -48,6 +47,15 @@ int idris2_fileErrno() { } } +int idris2_chmod(const char* path, mode_t mode) { +#ifdef _WIN32 + // return _chmod(path, mode); + return 0; /* ??? (from win_hack.c) */ +#else + return chmod(path, mode); +#endif +} + int idris2_removeFile(const char *filename) { return remove(filename); } diff --git a/support/c/idris_file.h b/support/c/idris_file.h index 0a1b6576a..4708b1543 100644 --- a/support/c/idris_file.h +++ b/support/c/idris_file.h @@ -1,8 +1,13 @@ #pragma once +#include #include #include +#ifdef _WIN32 +#include +#endif + FILE* idris2_openFile(char* name, char* mode); void idris2_closeFile(FILE* f); @@ -11,6 +16,7 @@ int idris2_fileError(FILE* f); // Turn errno into an integer understandable by System.File int idris2_fileErrno(); +int idris2_chmod(const char* path, mode_t mode); int idris2_removeFile(const char *filename); int idris2_fileSize(FILE* h); diff --git a/support/c/idris_net.c b/support/c/idris_net.c index 4e6916492..5aaf2a20c 100644 --- a/support/c/idris_net.c +++ b/support/c/idris_net.c @@ -78,6 +78,14 @@ int idrnet_socket(int domain, int type, int protocol) { return socket(domain, type, protocol); } +int idrnet_close(int fd) { +#ifdef _WIN32 + return _close(fd); +#else + return close(fd); +#endif +} + // Get the address family constants out of C and into Idris int idrnet_af_unspec() { return AF_UNSPEC; @@ -192,6 +200,18 @@ int idrnet_connect(int sockfd, int family, int socket_type, char* host, int port return 0; } +int idrnet_listen(int socket, int backlog) { + return listen(socket, backlog); +} + +FILE* idrnet_fdopen(int fd, const char* mode) { +#ifdef _WIN32 + return _fdopen(fd, mode); +#else + return fdopen(fd, mode); +#endif +} + int idrnet_sockaddr_family(void* sockaddr) { struct sockaddr* addr = (struct sockaddr*) sockaddr; diff --git a/support/c/idris_net.h b/support/c/idris_net.h index b0ab050b5..3cba732d8 100644 --- a/support/c/idris_net.h +++ b/support/c/idris_net.h @@ -1,7 +1,11 @@ #pragma once +#include +#include + // Includes used by the idris-file. #ifdef _WIN32 +#include #include #include #else @@ -45,6 +49,7 @@ void idrnet_poke(void *ptr, unsigned int offset, char val); int idrnet_errno(); int idrnet_socket(int domain, int type, int protocol); +int idrnet_close(int fd); // Address family accessors int idrnet_af_unspec(void); @@ -61,6 +66,10 @@ int idrnet_getsockname(int sockfd, void *address, void *len); // Connect int idrnet_connect(int sockfd, int family, int socket_type, char* host, int port); +// Listen +int idrnet_listen(int socket, int backlog); +FILE* idrnet_fdopen(int fd, const char* mode); + // Accessor functions for struct_sockaddr int idrnet_sockaddr_family(void* sockaddr); char* idrnet_sockaddr_ipv4(void* sockaddr); diff --git a/support/c/windows/win_utils.c b/support/c/windows/win_utils.c index 7f7fbaad9..4804aac44 100644 --- a/support/c/windows/win_utils.c +++ b/support/c/windows/win_utils.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include diff --git a/support/racket/support.rkt b/support/racket/support.rkt index a602d22fb..c9b4dce32 100644 --- a/support/racket/support.rkt +++ b/support/racket/support.rkt @@ -1,7 +1,7 @@ (define (blodwen-os) (case (system-type 'os) [(unix) "unix"] - [(osx) "darwin"] + [(macosx) "darwin"] [(windows) "windows"] [else "unknown"])) diff --git a/support/refc/Makefile b/support/refc/Makefile index 338f0a312..de52f20a1 100644 --- a/support/refc/Makefile +++ b/support/refc/Makefile @@ -4,18 +4,16 @@ TARGET = libidris2_refc LIBTARGET = $(TARGET).a -CFLAGS += -O2 - -SRCS = $(wildcard *.c) -ifeq ($(OS), windows) - LDFLAGS += -lws2_32 -ifeq ($(OLD_WIN), 1) - CFLAGS += -D_OLD_WIN -endif -endif +SRCS := $(wildcard *.c) OBJS = $(SRCS:.c=.o) DEPS = $(OBJS:.o=.d) +CFLAGS += -O2 + +ifeq ($(OLD_WIN), 1) + CPPFLAGS += -D_OLD_WIN +endif + all: build