mirror of
https://github.com/idris-lang/Idris2.git
synced 2024-11-23 22:22:07 +03:00
[fix] Loading libidris2_support.dll with Racket (#1583)
This commit is contained in:
parent
5f34801200
commit
74db7714d4
57
.github/workflows/ci-idris2.yml
vendored
57
.github/workflows/ci-idris2.yml
vendored
@ -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
|
||||
######################################################################
|
||||
|
@ -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"
|
||||
|
@ -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" "$@"
|
||||
|
@ -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" "$@"
|
||||
|
13
config.mk
13
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
|
||||
|
@ -95,7 +95,7 @@ prim__stdout : FilePtr
|
||||
"node:lambda:x=>({fd:2, buffer: Buffer.alloc(0), name:'<stderr>', 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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 ++ "\" "
|
||||
++ "\"$@\""
|
||||
|
@ -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 ->
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
@ -5,7 +5,6 @@
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
@ -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);
|
||||
}
|
||||
|
@ -1,8 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <io.h>
|
||||
#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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -1,7 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
// Includes used by the idris-file.
|
||||
#ifdef _WIN32
|
||||
#include <io.h>
|
||||
#include <winsock2.h>
|
||||
#include <Ws2tcpip.h>
|
||||
#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);
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <io.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
#include <process.h>
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
(define (blodwen-os)
|
||||
(case (system-type 'os)
|
||||
[(unix) "unix"]
|
||||
[(osx) "darwin"]
|
||||
[(macosx) "darwin"]
|
||||
[(windows) "windows"]
|
||||
[else "unknown"]))
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user