From 91944110e86b684f259fcd8f9e5e54f18f3902b7 Mon Sep 17 00:00:00 2001 From: Kooda Date: Tue, 14 Aug 2018 09:40:52 +0200 Subject: [PATCH 1/2] Make static linking work on Windows --- csc.scm | 3 ++- distribution/manifest | 1 + tests/csc-tests.scm | 7 +++++-- tests/module-static-link.scm | 3 +++ tests/runtests.bat | 16 ++++++++++++++-- tests/runtests.sh | 7 +++++++ 6 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 tests/module-static-link.scm diff --git a/csc.scm b/csc.scm index 2c3c4ce6..75074ee8 100644 --- a/csc.scm +++ b/csc.scm @@ -63,6 +63,7 @@ ;;; Parameters: +(define windows (eq? (software-type) 'windows)) (define mingw (eq? (software-version) 'mingw32)) (define osx (eq? (software-version) 'macosx)) (define cygwin (eq? (software-version) 'cygwin)) @@ -101,7 +102,7 @@ (define rc-compiler (quotewrap (if host-mode INSTALL_RC_COMPILER TARGET_RC_COMPILER))) (define linker (quotewrap (if host-mode host-cc default-cc))) (define c++-linker (quotewrap (if host-mode host-cxx default-cxx))) -(define object-extension "o") +(define object-extension (if windows "obj" "o")) (define library-extension "a") (define link-output-flag "-o ") (define executable-extension "") diff --git a/distribution/manifest b/distribution/manifest index fd108087..4a5ca459 100644 --- a/distribution/manifest +++ b/distribution/manifest @@ -159,6 +159,7 @@ tests/test-glob.scm tests/matchable.scm tests/module-tests.scm tests/module-static-eval-compiled.scm +tests/module-static-link.scm tests/module-tests-2.scm tests/multiple-values.scm tests/test-finalizers.scm diff --git a/tests/csc-tests.scm b/tests/csc-tests.scm index 6eba87b7..0bb8a11a 100644 --- a/tests/csc-tests.scm +++ b/tests/csc-tests.scm @@ -2,6 +2,7 @@ (import (chicken file) (chicken pathname) + (chicken platform) (chicken process) (chicken process-context) (chicken string)) @@ -20,8 +21,10 @@ (csc "null.scm" "-t") (assert (file-exists? "null.c")) +(define obj-file (if (eq? (software-type) 'windows) "null.obj" "null.o")) + (csc "null.c" "-c") -(assert (file-exists? "null.o")) +(assert (file-exists? obj-file)) -(csc "null.o") +(csc obj-file) (run "null") diff --git a/tests/module-static-link.scm b/tests/module-static-link.scm new file mode 100644 index 00000000..84b89bea --- /dev/null +++ b/tests/module-static-link.scm @@ -0,0 +1,3 @@ +(module main () +(import scheme chicken.base sample-module) +(assert (= foo 42))) diff --git a/tests/runtests.bat b/tests/runtests.bat index abacfeb1..e9dcdb33 100644 --- a/tests/runtests.bat +++ b/tests/runtests.bat @@ -19,6 +19,7 @@ set COMPILE_OPTIONS=-v -compiler %CHICKEN% -I%TEST_DIR%/.. -L%TEST_DIR%/.. -incl set compile=..\%PROGRAM_PREFIX%csc%PROGRAM_SUFFIX% %COMPILE_OPTIONS% -o a.out -types %TYPESDB% -ignore-repository set compile_r=..\%PROGRAM_PREFIX%csc%PROGRAM_SUFFIX% %COMPILE_OPTIONS% -o a.out +set compile_raw=..\%PROGRAM_PREFIX%csc%PROGRAM_SUFFIX% %COMPILE_OPTIONS% set compile_s=..\%PROGRAM_PREFIX%csc%PROGRAM_SUFFIX% %COMPILE_OPTIONS% -s -types %TYPESDB% -ignore-repository set interpret=..\%PROGRAM_PREFIX%csi%PROGRAM_SUFFIX% -n -include-path %TEST_DIR%/.. @@ -425,6 +426,17 @@ if errorlevel 1 exit /b 1 rem %compile% ec-tests.scm rem a.out # takes ages to compile +echo ======================================== module tests (static link) ... +%compile_raw% -static -unit sample-module -J -c sample-module.scm +if errorlevel 1 exit /b 1 +copy sample-module.link %CHICKEN_INSTALL_REPOSITORY% +copy sample-module.import.scm %CHICKEN_INSTALL_REPOSITORY% +copy sample-module.o %CHICKEN_INSTALL_REPOSITORY% +%compile_r% -static module-static-link.scm +if errorlevel 1 exit /b 1 +a.out +if errorlevel 1 exit /b 1 + echo ======================================== port tests ... %interpret% -s port-tests.scm if errorlevel 1 exit /b 1 @@ -613,7 +625,7 @@ a.out if errorlevel 1 exit /b 1 echo ======================================== linking tests ... -%compile_r% -unit reverser reverser\tags\1.0\reverser.scm -J -c -o reverser.o +%compile_r% -unit reverser reverser\tags\1.0\reverser.scm -J -c -o reverser.obj %compile_r% -link reverser linking-tests.scm if errorlevel 1 exit /b 1 a.out @@ -622,7 +634,7 @@ if errorlevel 1 exit /b 1 if errorlevel 1 exit /b 1 a.out if errorlevel 1 exit /b 1 -move reverser.o %CHICKEN_INSTALL_REPOSITORY% +move reverser.obj %CHICKEN_INSTALL_REPOSITORY% move reverser.import.scm %CHICKEN_INSTALL_REPOSITORY% %compile_r% -link reverser linking-tests.scm if errorlevel 1 exit /b 1 diff --git a/tests/runtests.sh b/tests/runtests.sh index 0232e7bd..c37b61ea 100755 --- a/tests/runtests.sh +++ b/tests/runtests.sh @@ -46,6 +46,7 @@ COMPILE_OPTIONS="-v -compiler ${CHICKEN} -I${TEST_DIR}/.. -L${TEST_DIR}/.. -incl compile="../${PROGRAM_PREFIX}csc${PROGRAM_SUFFIX} ${COMPILE_OPTIONS} -o a.out -types ${TYPESDB} -ignore-repository" compile_r="../${PROGRAM_PREFIX}csc${PROGRAM_SUFFIX} ${COMPILE_OPTIONS} -o a.out" +compile_raw="../${PROGRAM_PREFIX}csc${PROGRAM_SUFFIX} ${COMPILE_OPTIONS}" compile_s="../${PROGRAM_PREFIX}csc${PROGRAM_SUFFIX} ${COMPILE_OPTIONS} -s -types ${TYPESDB} -ignore-repository" interpret="../${PROGRAM_PREFIX}csi${PROGRAM_SUFFIX} -n -include-path ${TEST_DIR}/.." time=time @@ -338,6 +339,12 @@ $interpret -bnq ec.so ec-tests.scm # $compile ec-tests.scm # ./a.out # takes ages to compile +echo "======================================== module tests (static link) ..." +$compile_raw -static -unit sample-module -J -c sample-module.scm +cp sample-module.link sample-module.import.scm sample-module.o $CHICKEN_INSTALL_REPOSITORY +$compile_r -static module-static-link.scm +./a.out + echo "======================================== port tests ..." $interpret -s port-tests.scm -- 2.18.0