Windows support

This commit is contained in:
Niklas Larsson 2020-05-20 18:14:38 +02:00
parent 8291c8bbeb
commit d50bb099ea
9 changed files with 106 additions and 24 deletions

View File

@ -12,6 +12,7 @@ MAJOR=0
MINOR=2
PATCH=0
GIT_SHA1=
ifeq ($(shell git status >/dev/null 2>&1; echo $$?), 0)
# inside a git repo
@ -31,7 +32,17 @@ else
IDRIS2_IPKG := idris2rkt.ipkg
endif
export IDRIS2_BOOT_PATH = ${CURDIR}/libs/prelude/build/ttc:${CURDIR}/libs/base/build/ttc:${CURDIR}/libs/network/build/ttc
ifeq ($(OS), windows)
IDRIS2_PREFIX := $(shell cygpath -m ${PREFIX})
IDRIS2_CURDIR := $(shell cygpath -m ${CURDIR})
export IDRIS2_BOOT_PATH = "${IDRIS2_CURDIR}/libs/prelude/build/ttc;${IDRIS2_CURDIR}/libs/base/build/ttc;${IDRIS2_CURDIR}/libs/network/build/ttc"
else
IDRIS2_PREFIX := ${PREFIX}
IDRIS2_CURDIR := ${CURDIR}
export IDRIS2_BOOT_PATH = ${IDRIS2_CURDIR}/libs/prelude/build/ttc:${IDRIS2_CURDIR}/libs/base/build/ttc:${IDRIS2_CURDIR}/libs/network/build/ttc
endif
export SCHEME
@ -48,7 +59,7 @@ ${TARGET}: src/IdrisPaths.idr
src/IdrisPaths.idr:
echo 'module IdrisPaths' > src/IdrisPaths.idr
echo 'export idrisVersion : ((Nat,Nat,Nat), String); idrisVersion = ((${MAJOR},${MINOR},${PATCH}), "${GIT_SHA1}")' >> src/IdrisPaths.idr
echo 'export yprefix : String; yprefix="${PREFIX}"' >> src/IdrisPaths.idr
echo 'export yprefix : String; yprefix="${IDRIS2_PREFIX}"' >> src/IdrisPaths.idr
prelude:
${MAKE} -C libs/prelude IDRIS2=../../${TARGET} IDRIS2_PATH=${IDRIS2_BOOT_PATH}
@ -122,19 +133,23 @@ bootstrap: support
cp support/c/${IDRIS2_SUPPORT} bootstrap/idris2_app
sed s/libidris2_support.so/${IDRIS2_SUPPORT}/g bootstrap/idris2_app/idris2.ss > bootstrap/idris2_app/idris2-boot.ss
ifeq ($(OS), darwin)
sed -i '' 's|__PREFIX__|${CURDIR}/bootstrap|g' bootstrap/idris2_app/idris2-boot.ss
sed -i '' 's|__PREFIX__|${IDRIS2_CURDIR}/bootstrap|g' bootstrap/idris2_app/idris2-boot.ss
else
sed -i 's|__PREFIX__|${CURDIR}/bootstrap|g' bootstrap/idris2_app/idris2-boot.ss
sed -i 's|__PREFIX__|${IDRIS2_CURDIR}/bootstrap|g' bootstrap/idris2_app/idris2-boot.ss
endif
ifeq ($(OS), windows)
sh ./bootstrap-win.sh
else
sh ./bootstrap.sh
endif
bootstrap-racket: support
cp support/c/${IDRIS2_SUPPORT} bootstrap/idris2_app
cp bootstrap/idris2.rkt bootstrap/idris2boot.rkt
ifeq ($(OS), darwin)
sed -i '' 's|__PREFIX__|${CURDIR}/bootstrap|g' bootstrap/idris2boot.rkt
sed -i '' 's|__PREFIX__|${IDRIS2_CURDIR}/bootstrap|g' bootstrap/idris2boot.rkt
else
sed -i 's|__PREFIX__|${CURDIR}/bootstrap|g' bootstrap/idris2boot.rkt
sed -i 's|__PREFIX__|${IDRIS2_CURDIR}/bootstrap|g' bootstrap/idris2boot.rkt
endif
sh ./bootstrap-rkt.sh

35
bootstrap-win.sh Normal file
View File

@ -0,0 +1,35 @@
#!/bin/sh
if [ -z "$SCHEME" ]
then
echo "SCHEME not set. Invoke with SCHEME=[name of chez executable]"
exit 1
fi
# Compile the bootstrap scheme
cd bootstrap
${SCHEME} --script compile.ss
# Put the result in the usual place where the target goes
mkdir -p ../build/exec
mkdir -p ../build/exec/idris2_app
install idris2-boot ../build/exec/idris2
install idris2_app/* ../build/exec/idris2_app
cd ..
# Install with the bootstrap directory as the PREFIX
DIR="`realpath $0`"
PREFIX="`dirname $DIR`"/bootstrap
WIN_PREFIX=$(cygpath -m $PREFIX)
# Now rebuild everything properly
echo ${PREFIX}
IDRIS2_BOOT_PATH="${WIN_PREFIX}/idris2-0.2.0/prelude;${WIN_PREFIX}/idris2-0.2.0/base;${WIN_PREFIX}/idris2-0.2.0/contrib;${WIN_PREFIX}/idris2-0.2.0/network"
make libs SCHEME=${SCHEME} PREFIX=${PREFIX}
make install SCHEME=${SCHEME} PREFIX=${PREFIX}
make clean IDRIS2_BOOT=${PREFIX}/bin/idris2
make all IDRIS2_BOOT=${PREFIX}/bin/idris2 SCHEME=${SCHEME} IDRIS2_PATH=${IDRIS2_BOOT_PATH}
make test INTERACTIVE='' IDRIS2_BOOT=${PREFIX}/bin/idris2 SCHEME=${SCHEME} IDRIS2_PATH=${IDRIS2_BOOT_PATH} IDRIS2_LIBS=${WIN_PREFIX}/idris2-0.2.0/lib IDRIS2_DATA=${WIN_PREFIX}/idris2-0.2.0/support

View File

@ -1,5 +1,5 @@
#!/bin/sh
DIR="`realpath $0`"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:`dirname "$DIR"`/"idris2_app""
export PATH="`dirname "$DIR"`/"idris2_app":$PATH"
${SCHEME} --script "`dirname $DIR`"/"idris2_app/idris2-boot.so" "$@"

View File

@ -26,9 +26,9 @@ import System.Info
pathLookup : IO String
pathLookup
= do path <- getEnv "PATH"
let pathList = split (== ':') $ fromMaybe "/usr/bin:/usr/local/bin" path
let pathList = split (== pathSep) $ fromMaybe "/usr/bin:/usr/local/bin" path
let candidates = [p ++ "/" ++ x | p <- pathList,
x <- ["chez", "chezscheme9.5", "scheme"]]
x <- ["chez", "chezscheme9.5", "scheme", "scheme.exe"]]
e <- firstExists candidates
pure $ fromMaybe "/usr/bin/env scheme" e
@ -316,6 +316,23 @@ startChez appdir target = unlines
, "\"`dirname \"$DIR\"`\"/\"" ++ target ++ "\" \"$@\""
]
startChezCmd : String -> String -> String -> String
startChezCmd chez appdir target = unlines
[ "@echo off"
, "set APPDIR=%~dp0"
, "set PATH=%APPDIR%;%PATH%"
, chez ++ " --script %APPDIR%/" ++ target ++ " %*"
]
startChezWinSh : String -> String -> String -> String
startChezWinSh chez appdir target = unlines
[ "#!/bin/sh"
, "DIR=\"`realpath $0`\""
, "CHEZ=$(cygpath \"" ++ chez ++"\")"
, "export PATH=\"`dirname \"$DIR\"`/\"" ++ appdir ++ "\":$PATH\""
, "$CHEZ --script \"`dirname \"$DIR\"`\"/\"" ++ target ++ "\" \"$@\""
]
||| Compile a TT expression to Chez Scheme
compileToSS : Ref Ctxt Defs ->
String -> ClosedTerm -> (outfile : String) -> Core ()
@ -347,17 +364,15 @@ compileToSS c appdir tm outfile
||| Compile a Chez Scheme source file to an executable, daringly with runtime checks off.
compileToSO : {auto c : Ref Ctxt Defs} ->
(appDirRel : String) -> (outSsAbs : String) -> Core ()
compileToSO appDirRel outSsAbs
String -> (appDirRel : String) -> (outSsAbs : String) -> Core ()
compileToSO chez appDirRel outSsAbs
= do let tmpFileAbs = appDirRel ++ dirSep ++ "compileChez"
chez <- coreLift $ findChez
let build= "#!" ++ chez ++ " --script\n" ++
"(parameterize ([optimize-level 3]) (compile-program \"" ++
outSsAbs ++ "\"))"
let build= "(parameterize ([optimize-level 3]) (compile-program " ++
show outSsAbs ++ "))"
Right () <- coreLift $ writeFile tmpFileAbs build
| Left err => throw (FileErr tmpFileAbs err)
coreLift $ chmodRaw tmpFileAbs 0o755
coreLift $ system tmpFileAbs
coreLift $ system (chez ++ " --script " ++ tmpFileAbs)
pure ()
makeSh : String -> String -> String -> Core ()
@ -366,13 +381,22 @@ makeSh outShRel appdir outAbs
| Left err => throw (FileErr outShRel err)
pure ()
||| Make Windows start scripts, one for bash environments and one batch file
makeShWindows : String -> String -> String -> String -> Core ()
makeShWindows chez outShRel appdir outAbs
= do let cmdFile = outShRel ++ ".cmd"
Right () <- coreLift $ writeFile cmdFile (startChezCmd chez appdir outAbs)
| Left err => throw (FileErr cmdFile err)
Right () <- coreLift $ writeFile outShRel (startChezWinSh chez appdir outAbs)
| Left err => throw (FileErr outShRel err)
pure ()
||| Chez Scheme implementation of the `compileExpr` interface.
compileExpr : Bool -> Ref Ctxt Defs -> (execDir : String) ->
ClosedTerm -> (outfile : String) -> Core (Maybe String)
compileExpr makeitso c execDir tm outfile
= do let appDirRel = outfile ++ "_app" -- relative to build dir
let appDirGen = execDir ++ dirSep ++ appDirRel -- relative to here
coreLift $ mkdirs (splitDir appDirGen)
Just cwd <- coreLift currentDir
| Nothing => throw (InternalError "Can't get current directory")
@ -380,11 +404,13 @@ compileExpr makeitso c execDir tm outfile
let outSoFile = appDirRel ++ dirSep ++ outfile ++ ".so"
let outSsAbs = cwd ++ dirSep ++ execDir ++ dirSep ++ outSsFile
let outSoAbs = cwd ++ dirSep ++ execDir ++ dirSep ++ outSoFile
chez <- coreLift $ findChez
compileToSS c appDirGen tm outSsAbs
logTime "Make SO" $ when makeitso $ compileToSO appDirGen outSsAbs
logTime "Make SO" $ when makeitso $ compileToSO chez appDirGen outSsAbs
let outShRel = execDir ++ dirSep ++ outfile
makeSh outShRel appDirRel (if makeitso then outSoFile else outSsFile)
if isWindows
then makeShWindows chez outShRel appDirRel (if makeitso then outSoFile else outSsFile)
else makeSh outShRel appDirRel (if makeitso then outSoFile else outSsFile)
coreLift $ chmodRaw outShRel 0o755
pure (Just outShRel)

View File

@ -129,12 +129,13 @@ record Options where
primnames : PrimNames
extensions : List LangExt
export
isWindows : Bool
isWindows = os `elem` ["windows", "mingw32", "cygwin32"]
export
sep : Char
sep = '/'
sep = if isWindows then '\\' else '/'
export
dirSep : String

View File

@ -9,7 +9,7 @@ CFLAGS += -O2
SRCS = $(wildcard *.c)
ifeq ($(OS), windows)
SRCS += windows/win_utils.c
SRCS += windows/win_utils.c windows/win_hack.c
endif
OBJS = $(SRCS:.c=.o)
DEPS = $(OBJS:.o=.d)

View File

@ -0,0 +1,3 @@
int chmod(char** str, int perm) {
return 0;
}

View File

@ -7,6 +7,7 @@ import Data.Strings
import System
import System.Directory
import System.File
import System.Path
%default covering
@ -228,9 +229,9 @@ firstExists (x :: xs) = if !(exists x) then pure (Just x) else firstExists xs
pathLookup : IO (Maybe String)
pathLookup = do
path <- getEnv "PATH"
let pathList = split (== ':') $ fromMaybe "/usr/bin:/usr/local/bin" path
let pathList = split (== pathSeparator) $ fromMaybe "/usr/bin:/usr/local/bin" path
let candidates = [p ++ "/" ++ x | p <- pathList,
x <- ["chez", "chezscheme9.5", "scheme"]]
x <- ["chez", "chezscheme9.5", "scheme", "scheme.exe"]]
firstExists candidates
findChez : IO (Maybe String)

View File

@ -1,4 +1,5 @@
package runtests
depends = contrib
main = Main
executable = runtests