From 223f68d2325a5b508dce224ca4320be84e87b3b7 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Thu, 9 Jan 2020 10:55:56 -0800 Subject: [PATCH 01/14] enable testing -d:nimHasLibFFI mode --- koch.nim | 6 +++--- tests/vm/tevalffi.nim | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/koch.nim b/koch.nim index 57302843aca28..dcce21a21de12 100644 --- a/koch.nim +++ b/koch.nim @@ -485,9 +485,9 @@ proc runCI(cmd: string) = ## build nimble early on to enable remainder to depend on it if needed kochExecFold("Build Nimble", "nimble") - when false: - execFold("nimble install -y libffi", "nimble install -y libffi") - kochExecFold("boot -d:release -d:nimHasLibFFI", "boot -d:release -d:nimHasLibFFI") + ## test -d:nimHasLibFFI + execFold("nimble install -y libffi", "nimble install -y libffi") + kochExecFold("boot -d:release -d:nimHasLibFFI", "boot -d:release -d:nimHasLibFFI") if getEnv("NIM_TEST_PACKAGES", "false") == "true": execFold("Test selected Nimble packages", "nim c -r testament/testament cat nimble-packages") diff --git a/tests/vm/tevalffi.nim b/tests/vm/tevalffi.nim index c2abdba5d0f1a..d72ddccaeda05 100644 --- a/tests/vm/tevalffi.nim +++ b/tests/vm/tevalffi.nim @@ -22,7 +22,6 @@ ret={s1:foobar s2:foobar age:25 pi:3.14} hello world stderr hi stderr ''' - disabled: "true" """ # re-enable for windows once libffi can be installed in koch.nim From c0bd51171d1f8ea2dedd20319c97699b5a15be9f Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Thu, 9 Jan 2020 11:38:14 -0800 Subject: [PATCH 02/14] fixup --- koch.nim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/koch.nim b/koch.nim index dcce21a21de12..f76b3f45a1e81 100644 --- a/koch.nim +++ b/koch.nim @@ -486,7 +486,9 @@ proc runCI(cmd: string) = kochExecFold("Build Nimble", "nimble") ## test -d:nimHasLibFFI - execFold("nimble install -y libffi", "nimble install -y libffi") + ## pending https://github.com/Araq/libffi/pull/4 + # execFold("nimble install -y libffi", "nimble install -y libffi") + execFold("nimble install -y https://github.com/timotheecour/libffi@9617720caba60ebd458fc1470f7b49ba19d32006", "nimble install -y libffi") kochExecFold("boot -d:release -d:nimHasLibFFI", "boot -d:release -d:nimHasLibFFI") if getEnv("NIM_TEST_PACKAGES", "false") == "true": From c351ce89de3b93e632f80902b177ea744dddc1b3 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 29 Jan 2020 10:57:11 -0800 Subject: [PATCH 03/14] fixup --- koch.nim | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/koch.nim b/koch.nim index f76b3f45a1e81..dcce21a21de12 100644 --- a/koch.nim +++ b/koch.nim @@ -486,9 +486,7 @@ proc runCI(cmd: string) = kochExecFold("Build Nimble", "nimble") ## test -d:nimHasLibFFI - ## pending https://github.com/Araq/libffi/pull/4 - # execFold("nimble install -y libffi", "nimble install -y libffi") - execFold("nimble install -y https://github.com/timotheecour/libffi@9617720caba60ebd458fc1470f7b49ba19d32006", "nimble install -y libffi") + execFold("nimble install -y libffi", "nimble install -y libffi") kochExecFold("boot -d:release -d:nimHasLibFFI", "boot -d:release -d:nimHasLibFFI") if getEnv("NIM_TEST_PACKAGES", "false") == "true": From 9bc3ad85bb7616bcec3a39715ead652b227a6018 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 29 Jan 2020 12:52:43 -0800 Subject: [PATCH 04/14] fix test --- tests/vm/tevalffi.nim | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/vm/tevalffi.nim b/tests/vm/tevalffi.nim index d72ddccaeda05..90d474f43723f 100644 --- a/tests/vm/tevalffi.nim +++ b/tests/vm/tevalffi.nim @@ -1,6 +1,8 @@ discard """ cmd: "nim c --experimental:compiletimeFFI $file" nimout: ''' +hello world stderr +hi stderr foo foo:100 foo:101 @@ -8,10 +10,10 @@ foo:102:103 foo:102:103:104 foo:0.03:asdf:103:105 ret={s1:foobar s2:foobar age:25 pi:3.14} -hello world stderr -hi stderr ''' output: ''' +hello world stderr +hi stderr foo foo:100 foo:101 @@ -19,8 +21,6 @@ foo:102:103 foo:102:103:104 foo:0.03:asdf:103:105 ret={s1:foobar s2:foobar age:25 pi:3.14} -hello world stderr -hi stderr ''' """ @@ -84,8 +84,8 @@ static: fun() fun() -when true: - import system/ansi_c +import system/ansi_c +block: proc fun2()= c_fprintf(cstderr, "hello world stderr\n") write(stderr, "hi stderr\n") From 8c2a5d84650eb8cd7108d622d71ed784d1078161 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 29 Jan 2020 15:17:07 -0800 Subject: [PATCH 05/14] fix for i386 linux --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 0898755b61638..359aa461c56f8 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -77,7 +77,7 @@ jobs: DEBIAN_FRONTEND='noninteractive' \ sudo apt-fast install --no-install-recommends --allow-downgrades -yq \ g++-multilib gcc-multilib libcurl4-openssl-dev:i386 libgc-dev:i386 \ - libsdl1.2-dev:i386 libsfml-dev:i386 libglib2.0-dev:i386 + libsdl1.2-dev:i386 libsfml-dev:i386 libglib2.0-dev:i386 libffi-dev cat << EOF > bin/gcc #!/bin/bash From 182439e1a8767a914e3f6efa1a5a01ccab796445 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 29 Jan 2020 20:04:29 -0800 Subject: [PATCH 06/14] fixup --- azure-pipelines.yml | 4 +++- koch.nim | 11 +++++++---- tests/vm/tevalffi.nim | 1 + 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 359aa461c56f8..dccd0d05e75fc 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -74,10 +74,12 @@ jobs: EOF sudo apt-fast update -qq + # `:i386` (e.g. in `libffi-dev:i386`) is needed otherwise you may get: + # `could not load: libffi.so` during dynamic loading. DEBIAN_FRONTEND='noninteractive' \ sudo apt-fast install --no-install-recommends --allow-downgrades -yq \ g++-multilib gcc-multilib libcurl4-openssl-dev:i386 libgc-dev:i386 \ - libsdl1.2-dev:i386 libsfml-dev:i386 libglib2.0-dev:i386 libffi-dev + libsdl1.2-dev:i386 libsfml-dev:i386 libglib2.0-dev:i386 libffi-dev:i386 cat << EOF > bin/gcc #!/bin/bash diff --git a/koch.nim b/koch.nim index dcce21a21de12..bf1c59ac571ff 100644 --- a/koch.nim +++ b/koch.nim @@ -485,10 +485,6 @@ proc runCI(cmd: string) = ## build nimble early on to enable remainder to depend on it if needed kochExecFold("Build Nimble", "nimble") - ## test -d:nimHasLibFFI - execFold("nimble install -y libffi", "nimble install -y libffi") - kochExecFold("boot -d:release -d:nimHasLibFFI", "boot -d:release -d:nimHasLibFFI") - if getEnv("NIM_TEST_PACKAGES", "false") == "true": execFold("Test selected Nimble packages", "nim c -r testament/testament cat nimble-packages") else: @@ -502,6 +498,13 @@ proc runCI(cmd: string) = # main bottleneck here execFold("Run tester", "nim c -r -d:nimCoroutines testament/testament --pedantic all -d:nimCoroutines") + block: # CT FFI + when defined(posix): # windows can be handled in future PR's + execFold("nimble install -y libffi", "nimble install -y libffi") + const nimFFI = "./bin/nim.ctffi" + # no need to bootstrap with koch boot (would be slower) + execFold("build with -d:nimHasLibFFI", "nim c -d:release -d:nimHasLibFFI -o:$1 compiler/nim.nim" % [nimFFI]) + execFold("test with -d:nimHasLibFFI", "nim c -r testament/testament --nim:$1 r tests/vm/tevalffi.nim" % [nimFFI]) execFold("Run nimdoc tests", "nim c -r nimdoc/tester") execFold("Run nimpretty tests", "nim c -r nimpretty/tester.nim") diff --git a/tests/vm/tevalffi.nim b/tests/vm/tevalffi.nim index 90d474f43723f..cf714933d511e 100644 --- a/tests/vm/tevalffi.nim +++ b/tests/vm/tevalffi.nim @@ -22,6 +22,7 @@ foo:102:103:104 foo:0.03:asdf:103:105 ret={s1:foobar s2:foobar age:25 pi:3.14} ''' + disabled: "windows" """ # re-enable for windows once libffi can be installed in koch.nim From a4edc80cf481fd2090f6a64902e74773efec0aff Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Thu, 30 Jan 2020 00:01:14 -0800 Subject: [PATCH 07/14] fix tests --- compiler/condsyms.nim | 6 ++++++ koch.nim | 2 +- testament/specs.nim | 2 ++ tests/vm/tevalffi.nim | 4 ++-- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/compiler/condsyms.nim b/compiler/condsyms.nim index ec9b4a9f4e047..9a762d585b6f8 100644 --- a/compiler/condsyms.nim +++ b/compiler/condsyms.nim @@ -103,3 +103,9 @@ proc initDefines*(symbols: StringTableRef) = defineSymbol("nimNewShiftOps") defineSymbol("nimHasCursor") defineSymbol("nimHasExceptionsQuery") + + when defined(nimHasLibFFI): + # Renaming as we can't conflate input vs output define flags; e.g. this + # will report the right thing regardless of whether user adds + # `-d:nimHasLibFFI` in his user config. + defineSymbol("nimHasLibFFIEnabled") diff --git a/koch.nim b/koch.nim index bf1c59ac571ff..02c0b40a9677f 100644 --- a/koch.nim +++ b/koch.nim @@ -504,7 +504,7 @@ proc runCI(cmd: string) = const nimFFI = "./bin/nim.ctffi" # no need to bootstrap with koch boot (would be slower) execFold("build with -d:nimHasLibFFI", "nim c -d:release -d:nimHasLibFFI -o:$1 compiler/nim.nim" % [nimFFI]) - execFold("test with -d:nimHasLibFFI", "nim c -r testament/testament --nim:$1 r tests/vm/tevalffi.nim" % [nimFFI]) + execFold("test with -d:nimHasLibFFI", "$1 c -r testament/testament --nim:$1 r tests/vm/tevalffi.nim" % [nimFFI]) execFold("Run nimdoc tests", "nim c -r nimdoc/tester") execFold("Run nimpretty tests", "nim c -r nimpretty/tester.nim") diff --git a/testament/specs.nim b/testament/specs.nim index 70be6990ce3b2..d7d412eb0c0cd 100644 --- a/testament/specs.nim +++ b/testament/specs.nim @@ -236,6 +236,8 @@ proc parseSpec*(filename: string): TSpec = when defined(freebsd): result.err = reDisabled of "arm64": when defined(arm64): result.err = reDisabled + of "not defined(nimHasLibFFI)": # this could be generalized somehow + when not defined(nimHasLibFFI): result.err = reDisabled else: result.parseErrors.addLine "cannot interpret as a bool: ", e.value of "cmd": diff --git a/tests/vm/tevalffi.nim b/tests/vm/tevalffi.nim index cf714933d511e..c749841c2b777 100644 --- a/tests/vm/tevalffi.nim +++ b/tests/vm/tevalffi.nim @@ -22,7 +22,7 @@ foo:102:103:104 foo:0.03:asdf:103:105 ret={s1:foobar s2:foobar age:25 pi:3.14} ''' - disabled: "windows" + disabled: "not defined(nimHasLibFFI)" """ # re-enable for windows once libffi can be installed in koch.nim @@ -65,7 +65,7 @@ proc fun() = var buffer2: pointer = c_malloc(n) var s: cstring = "foobar" var age: cint = 25 - let j = c_snprintf(buffer2, n, "s1:%s s2:%s age:%d pi:%g", s, s, age, 3.14) + discard c_snprintf(buffer2, n, "s1:%s s2:%s age:%d pi:%g", s, s, age, 3.14) c_printf("ret={%s}\n", buffer2) c_free(buffer2) # not sure it has an effect From 239d9a766698032b3701b4f003df88097d4b8830 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Thu, 30 Jan 2020 00:26:32 -0800 Subject: [PATCH 08/14] fixup --- testament/specs.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testament/specs.nim b/testament/specs.nim index d7d412eb0c0cd..2b76aace21532 100644 --- a/testament/specs.nim +++ b/testament/specs.nim @@ -236,7 +236,7 @@ proc parseSpec*(filename: string): TSpec = when defined(freebsd): result.err = reDisabled of "arm64": when defined(arm64): result.err = reDisabled - of "not defined(nimHasLibFFI)": # this could be generalized somehow + of "not defined(nimhaslibffi)": # a bit hacky, this could be generalized somehow when not defined(nimHasLibFFI): result.err = reDisabled else: result.parseErrors.addLine "cannot interpret as a bool: ", e.value From 1f55ea9d5e4e272668c8bdf777faffba4f0c4067 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Thu, 30 Jan 2020 00:52:41 -0800 Subject: [PATCH 09/14] fixup --- azure-pipelines.yml | 40 ++++++++++++++++++++-------------------- compiler/evalffi.nim | 3 +++ koch.nim | 6 +++--- lib/system/ansi_c.nim | 2 +- lib/system/io.nim | 2 +- testament/specs.nim | 4 ++-- tests/vm/tevalffi.nim | 4 ++-- 7 files changed, 32 insertions(+), 29 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index dccd0d05e75fc..06ee56ea16318 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -5,26 +5,26 @@ jobs: strategy: matrix: - Linux_amd64: - vmImage: 'ubuntu-16.04' - CPU: amd64 - Linux_i386: - vmImage: 'ubuntu-16.04' - CPU: i386 - OSX_amd64: - vmImage: 'macOS-10.14' - CPU: amd64 - OSX_amd64_cpp: - vmImage: 'macOS-10.14' - CPU: amd64 - NIM_COMPILE_TO_CPP: true - Windows_amd64: - vmImage: 'windows-2019' - CPU: amd64 - Windows_amd64_pkg: - vmImage: 'windows-2019' - CPU: amd64 - NIM_TEST_PACKAGES: true + # Linux_amd64: + # vmImage: 'ubuntu-16.04' + # CPU: amd64 + # Linux_i386: + # vmImage: 'ubuntu-16.04' + # CPU: i386 + # OSX_amd64: + # vmImage: 'macOS-10.14' + # CPU: amd64 + # OSX_amd64_cpp: + # vmImage: 'macOS-10.14' + # CPU: amd64 + # NIM_COMPILE_TO_CPP: true + # Windows_amd64: + # vmImage: 'windows-2019' + # CPU: amd64 + # Windows_amd64_pkg: + # vmImage: 'windows-2019' + # CPU: amd64 + # NIM_TEST_PACKAGES: true pool: vmImage: $(vmImage) diff --git a/compiler/evalffi.nim b/compiler/evalffi.nim index 58b996e60876d..ad5d054fae8f0 100644 --- a/compiler/evalffi.nim +++ b/compiler/evalffi.nim @@ -17,6 +17,9 @@ when defined(windows): const libcDll = "msvcrt.dll" elif defined(linux): const libcDll = "libc.so(.6|.5|)" +elif defined(freebsd): + # const libcDll = "/usr/lib/libc.so" + const libcDll = "/lib/libc.so.7" elif defined(osx): const libcDll = "/usr/lib/libSystem.dylib" else: diff --git a/koch.nim b/koch.nim index 02c0b40a9677f..f9fa618784ca3 100644 --- a/koch.nim +++ b/koch.nim @@ -477,8 +477,8 @@ proc runCI(cmd: string) = echo "runCI:", cmd # note(@araq): Do not replace these commands with direct calls (eg boot()) # as that would weaken our testing efforts. - when defined(posix): # appveyor (on windows) didn't run this - kochExecFold("Boot", "boot") + # when defined(posix): # appveyor (on windows) didn't run this + # kochExecFold("Boot", "boot") # boot without -d:nimHasLibFFI to make sure this still works kochExecFold("Boot in release mode", "boot -d:release -d:danger") @@ -497,7 +497,7 @@ proc runCI(cmd: string) = execFold("Compile tester", "nim c -d:nimCoroutines --os:genode -d:posix --compileOnly testament/testament") # main bottleneck here - execFold("Run tester", "nim c -r -d:nimCoroutines testament/testament --pedantic all -d:nimCoroutines") + # execFold("Run tester", "nim c -r -d:nimCoroutines testament/testament --pedantic all -d:nimCoroutines") block: # CT FFI when defined(posix): # windows can be handled in future PR's execFold("nimble install -y libffi", "nimble install -y libffi") diff --git a/lib/system/ansi_c.nim b/lib/system/ansi_c.nim index cb2303b616d40..0adcd67f78065 100644 --- a/lib/system/ansi_c.nim +++ b/lib/system/ansi_c.nim @@ -117,7 +117,7 @@ type CFilePtr* = ptr CFile ## The type representing a file handle. # duplicated between io and ansi_c -const stdioUsesMacros = defined(osx) and not defined(emscripten) +const stdioUsesMacros = (defined(osx) or defined(freebsd)) and not defined(emscripten) const stderrName = when stdioUsesMacros: "__stderrp" else: "stderr" const stdoutName = when stdioUsesMacros: "__stdoutp" else: "stdout" const stdinName = when stdioUsesMacros: "__stdinp" else: "stdin" diff --git a/lib/system/io.nim b/lib/system/io.nim index 8e3acd0b9cedf..bfc90997918ff 100644 --- a/lib/system/io.nim +++ b/lib/system/io.nim @@ -36,7 +36,7 @@ type # text file handling: when not defined(nimscript) and not defined(js): # duplicated between io and ansi_c - const stdioUsesMacros = defined(osx) and not defined(emscripten) + const stdioUsesMacros = (defined(osx) or defined(freebsd)) and not defined(emscripten) const stderrName = when stdioUsesMacros: "__stderrp" else: "stderr" const stdoutName = when stdioUsesMacros: "__stdoutp" else: "stdout" const stdinName = when stdioUsesMacros: "__stdinp" else: "stdin" diff --git a/testament/specs.nim b/testament/specs.nim index 2b76aace21532..1fad2c0c6ba64 100644 --- a/testament/specs.nim +++ b/testament/specs.nim @@ -236,8 +236,8 @@ proc parseSpec*(filename: string): TSpec = when defined(freebsd): result.err = reDisabled of "arm64": when defined(arm64): result.err = reDisabled - of "not defined(nimhaslibffi)": # a bit hacky, this could be generalized somehow - when not defined(nimHasLibFFI): result.err = reDisabled + of "not defined(nimhaslibffienabled)": # a bit hacky, this could be generalized somehow + when not defined(nimHasLibFFIEnabled): result.err = reDisabled else: result.parseErrors.addLine "cannot interpret as a bool: ", e.value of "cmd": diff --git a/tests/vm/tevalffi.nim b/tests/vm/tevalffi.nim index c749841c2b777..496e03e82a466 100644 --- a/tests/vm/tevalffi.nim +++ b/tests/vm/tevalffi.nim @@ -22,13 +22,13 @@ foo:102:103:104 foo:0.03:asdf:103:105 ret={s1:foobar s2:foobar age:25 pi:3.14} ''' - disabled: "not defined(nimHasLibFFI)" + disabled: "not defined(nimHasLibFFIEnabled)" """ # re-enable for windows once libffi can be installed in koch.nim # With win32 (not yet win64), libffi on windows works and this test passes. -when defined(linux): +when defined(linux) or defined(freebsd): {.passL: "-lm".} # for exp proc c_exp(a: float64): float64 {.importc: "exp", header: "".} From 20d27b0ff6a5fd5f9584cd68ae0aaaf063b51cdf Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Thu, 30 Jan 2020 14:02:33 -0800 Subject: [PATCH 10/14] fix for freebsd, etc --- azure-pipelines.yml | 40 ++++++++++++++++++++-------------------- compiler/evalffi.nim | 1 - koch.nim | 6 +++--- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 06ee56ea16318..dccd0d05e75fc 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -5,26 +5,26 @@ jobs: strategy: matrix: - # Linux_amd64: - # vmImage: 'ubuntu-16.04' - # CPU: amd64 - # Linux_i386: - # vmImage: 'ubuntu-16.04' - # CPU: i386 - # OSX_amd64: - # vmImage: 'macOS-10.14' - # CPU: amd64 - # OSX_amd64_cpp: - # vmImage: 'macOS-10.14' - # CPU: amd64 - # NIM_COMPILE_TO_CPP: true - # Windows_amd64: - # vmImage: 'windows-2019' - # CPU: amd64 - # Windows_amd64_pkg: - # vmImage: 'windows-2019' - # CPU: amd64 - # NIM_TEST_PACKAGES: true + Linux_amd64: + vmImage: 'ubuntu-16.04' + CPU: amd64 + Linux_i386: + vmImage: 'ubuntu-16.04' + CPU: i386 + OSX_amd64: + vmImage: 'macOS-10.14' + CPU: amd64 + OSX_amd64_cpp: + vmImage: 'macOS-10.14' + CPU: amd64 + NIM_COMPILE_TO_CPP: true + Windows_amd64: + vmImage: 'windows-2019' + CPU: amd64 + Windows_amd64_pkg: + vmImage: 'windows-2019' + CPU: amd64 + NIM_TEST_PACKAGES: true pool: vmImage: $(vmImage) diff --git a/compiler/evalffi.nim b/compiler/evalffi.nim index ad5d054fae8f0..0aa8dd331fc7d 100644 --- a/compiler/evalffi.nim +++ b/compiler/evalffi.nim @@ -18,7 +18,6 @@ when defined(windows): elif defined(linux): const libcDll = "libc.so(.6|.5|)" elif defined(freebsd): - # const libcDll = "/usr/lib/libc.so" const libcDll = "/lib/libc.so.7" elif defined(osx): const libcDll = "/usr/lib/libSystem.dylib" diff --git a/koch.nim b/koch.nim index f9fa618784ca3..02c0b40a9677f 100644 --- a/koch.nim +++ b/koch.nim @@ -477,8 +477,8 @@ proc runCI(cmd: string) = echo "runCI:", cmd # note(@araq): Do not replace these commands with direct calls (eg boot()) # as that would weaken our testing efforts. - # when defined(posix): # appveyor (on windows) didn't run this - # kochExecFold("Boot", "boot") + when defined(posix): # appveyor (on windows) didn't run this + kochExecFold("Boot", "boot") # boot without -d:nimHasLibFFI to make sure this still works kochExecFold("Boot in release mode", "boot -d:release -d:danger") @@ -497,7 +497,7 @@ proc runCI(cmd: string) = execFold("Compile tester", "nim c -d:nimCoroutines --os:genode -d:posix --compileOnly testament/testament") # main bottleneck here - # execFold("Run tester", "nim c -r -d:nimCoroutines testament/testament --pedantic all -d:nimCoroutines") + execFold("Run tester", "nim c -r -d:nimCoroutines testament/testament --pedantic all -d:nimCoroutines") block: # CT FFI when defined(posix): # windows can be handled in future PR's execFold("nimble install -y libffi", "nimble install -y libffi") From 60dfce2a5bf13e7a557c7f08ee02a1f41adc4c61 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Mon, 3 Feb 2020 23:42:28 -0800 Subject: [PATCH 11/14] avoid `not defined(nimhaslibffienabled)` hack --- testament/specs.nim | 2 - tests/vm/mevalffi.nim | 67 +++++++++++++++++++++++++++++++ tests/vm/tevalffi.nim | 92 ++++++++----------------------------------- 3 files changed, 84 insertions(+), 77 deletions(-) create mode 100644 tests/vm/mevalffi.nim diff --git a/testament/specs.nim b/testament/specs.nim index 1fad2c0c6ba64..70be6990ce3b2 100644 --- a/testament/specs.nim +++ b/testament/specs.nim @@ -236,8 +236,6 @@ proc parseSpec*(filename: string): TSpec = when defined(freebsd): result.err = reDisabled of "arm64": when defined(arm64): result.err = reDisabled - of "not defined(nimhaslibffienabled)": # a bit hacky, this could be generalized somehow - when not defined(nimHasLibFFIEnabled): result.err = reDisabled else: result.parseErrors.addLine "cannot interpret as a bool: ", e.value of "cmd": diff --git a/tests/vm/mevalffi.nim b/tests/vm/mevalffi.nim new file mode 100644 index 0000000000000..3603488eb7ef4 --- /dev/null +++ b/tests/vm/mevalffi.nim @@ -0,0 +1,67 @@ +# re-enable for windows once libffi can be installed in koch.nim +# With win32 (not yet win64), libffi on windows works and this test passes. + +when defined(linux) or defined(freebsd): + {.passL: "-lm".} # for exp +proc c_exp(a: float64): float64 {.importc: "exp", header: "".} + +proc c_printf(frmt: cstring): cint {.importc: "printf", header: "", varargs, discardable.} + +const snprintfName = when defined(windows): "_snprintf" else: "snprintf" +proc c_snprintf*(buffer: pointer, buf_size: uint, format: cstring): cint {.importc: snprintfName, header: "", varargs .} + +proc c_malloc(size:uint):pointer {.importc:"malloc", header: "".} +proc c_free(p: pointer) {.importc:"free", header: "".} + +proc fun() = + block: # c_exp + var x = 0.3 + let b = c_exp(x) + let b2 = int(b*1_000_000) # avoids floating point equality + doAssert b2 == 1349858 + doAssert c_exp(0.3) == c_exp(x) + const x2 = 0.3 + doAssert c_exp(x2) == c_exp(x) + + block: # c_printf + c_printf("foo\n") + c_printf("foo:%d\n", 100) + c_printf("foo:%d\n", 101.cint) + c_printf("foo:%d:%d\n", 102.cint, 103.cint) + let temp = 104.cint + c_printf("foo:%d:%d:%d\n", 102.cint, 103.cint, temp) + var temp2 = 105.cint + c_printf("foo:%g:%s:%d:%d\n", 0.03, "asdf", 103.cint, temp2) + + block: # c_snprintf, c_malloc, c_free + let n: uint = 50 + var buffer2: pointer = c_malloc(n) + var s: cstring = "foobar" + var age: cint = 25 + discard c_snprintf(buffer2, n, "s1:%s s2:%s age:%d pi:%g", s, s, age, 3.14) + c_printf("ret={%s}\n", buffer2) + c_free(buffer2) # not sure it has an effect + + block: # c_printf bug + var a = 123 + var a2 = a.addr + #[ + bug: different behavior between CT RT in this case: + at CT, shows foo2:a=123 + at RT, shows foo2:a=
+ ]# + if false: + c_printf("foo2:a=%d\n", a2) + + +static: + fun() +fun() + +import system/ansi_c +block: + proc fun2()= + c_fprintf(cstderr, "hello world stderr\n") + write(stderr, "hi stderr\n") + static: fun2() + fun2() diff --git a/tests/vm/tevalffi.nim b/tests/vm/tevalffi.nim index 496e03e82a466..8306f01808259 100644 --- a/tests/vm/tevalffi.nim +++ b/tests/vm/tevalffi.nim @@ -1,6 +1,17 @@ discard """ - cmd: "nim c --experimental:compiletimeFFI $file" - nimout: ''' + joinable: false +""" + +import std/[strformat,os,osproc] + +proc main() = + const nim = getCurrentCompilerExe() + const file = currentSourcePath().parentDir / "mevalffi.nim" + let cmd = fmt"{nim} c -r -f --experimental:compiletimeFFI --hints:off {file}" + let (output, exitCode) = execCmdEx(cmd) + let expected = """ +hello world stderr +hi stderr hello world stderr hi stderr foo @@ -10,10 +21,6 @@ foo:102:103 foo:102:103:104 foo:0.03:asdf:103:105 ret={s1:foobar s2:foobar age:25 pi:3.14} -''' - output: ''' -hello world stderr -hi stderr foo foo:100 foo:101 @@ -21,74 +28,9 @@ foo:102:103 foo:102:103:104 foo:0.03:asdf:103:105 ret={s1:foobar s2:foobar age:25 pi:3.14} -''' - disabled: "not defined(nimHasLibFFIEnabled)" """ + doAssert output == expected, output + doAssert exitCode == 0 -# re-enable for windows once libffi can be installed in koch.nim -# With win32 (not yet win64), libffi on windows works and this test passes. - -when defined(linux) or defined(freebsd): - {.passL: "-lm".} # for exp -proc c_exp(a: float64): float64 {.importc: "exp", header: "".} - -proc c_printf(frmt: cstring): cint {.importc: "printf", header: "", varargs, discardable.} - -const snprintfName = when defined(windows): "_snprintf" else: "snprintf" -proc c_snprintf*(buffer: pointer, buf_size: uint, format: cstring): cint {.importc: snprintfName, header: "", varargs .} - -proc c_malloc(size:uint):pointer {.importc:"malloc", header: "".} -proc c_free(p: pointer) {.importc:"free", header: "".} - -proc fun() = - block: # c_exp - var x = 0.3 - let b = c_exp(x) - let b2 = int(b*1_000_000) # avoids floating point equality - doAssert b2 == 1349858 - doAssert c_exp(0.3) == c_exp(x) - const x2 = 0.3 - doAssert c_exp(x2) == c_exp(x) - - block: # c_printf - c_printf("foo\n") - c_printf("foo:%d\n", 100) - c_printf("foo:%d\n", 101.cint) - c_printf("foo:%d:%d\n", 102.cint, 103.cint) - let temp = 104.cint - c_printf("foo:%d:%d:%d\n", 102.cint, 103.cint, temp) - var temp2 = 105.cint - c_printf("foo:%g:%s:%d:%d\n", 0.03, "asdf", 103.cint, temp2) - - block: # c_snprintf, c_malloc, c_free - let n: uint = 50 - var buffer2: pointer = c_malloc(n) - var s: cstring = "foobar" - var age: cint = 25 - discard c_snprintf(buffer2, n, "s1:%s s2:%s age:%d pi:%g", s, s, age, 3.14) - c_printf("ret={%s}\n", buffer2) - c_free(buffer2) # not sure it has an effect - - block: # c_printf bug - var a = 123 - var a2 = a.addr - #[ - bug: different behavior between CT RT in this case: - at CT, shows foo2:a=123 - at RT, shows foo2:a=
- ]# - if false: - c_printf("foo2:a=%d\n", a2) - - -static: - fun() -fun() - -import system/ansi_c -block: - proc fun2()= - c_fprintf(cstderr, "hello world stderr\n") - write(stderr, "hi stderr\n") - static: fun2() - fun2() +when defined(nimHasLibFFIEnabled): + main() From cc9b77d842e7fa631ed52a2ba58c8b9635909977 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Mon, 3 Feb 2020 23:58:46 -0800 Subject: [PATCH 12/14] freebsd => bsd --- compiler/evalffi.nim | 2 +- lib/system/ansi_c.nim | 2 +- lib/system/io.nim | 2 +- tests/vm/mevalffi.nim | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/evalffi.nim b/compiler/evalffi.nim index 0aa8dd331fc7d..58c505a5bc1ec 100644 --- a/compiler/evalffi.nim +++ b/compiler/evalffi.nim @@ -17,7 +17,7 @@ when defined(windows): const libcDll = "msvcrt.dll" elif defined(linux): const libcDll = "libc.so(.6|.5|)" -elif defined(freebsd): +elif defined(bsd): const libcDll = "/lib/libc.so.7" elif defined(osx): const libcDll = "/usr/lib/libSystem.dylib" diff --git a/lib/system/ansi_c.nim b/lib/system/ansi_c.nim index 0adcd67f78065..1ff15611c3875 100644 --- a/lib/system/ansi_c.nim +++ b/lib/system/ansi_c.nim @@ -117,7 +117,7 @@ type CFilePtr* = ptr CFile ## The type representing a file handle. # duplicated between io and ansi_c -const stdioUsesMacros = (defined(osx) or defined(freebsd)) and not defined(emscripten) +const stdioUsesMacros = (defined(osx) or defined(bsd)) and not defined(emscripten) const stderrName = when stdioUsesMacros: "__stderrp" else: "stderr" const stdoutName = when stdioUsesMacros: "__stdoutp" else: "stdout" const stdinName = when stdioUsesMacros: "__stdinp" else: "stdin" diff --git a/lib/system/io.nim b/lib/system/io.nim index bfc90997918ff..5f4c7d6d712ea 100644 --- a/lib/system/io.nim +++ b/lib/system/io.nim @@ -36,7 +36,7 @@ type # text file handling: when not defined(nimscript) and not defined(js): # duplicated between io and ansi_c - const stdioUsesMacros = (defined(osx) or defined(freebsd)) and not defined(emscripten) + const stdioUsesMacros = (defined(osx) or defined(bsd)) and not defined(emscripten) const stderrName = when stdioUsesMacros: "__stderrp" else: "stderr" const stdoutName = when stdioUsesMacros: "__stdoutp" else: "stdout" const stdinName = when stdioUsesMacros: "__stdinp" else: "stdin" diff --git a/tests/vm/mevalffi.nim b/tests/vm/mevalffi.nim index 3603488eb7ef4..e15ed8f74dd09 100644 --- a/tests/vm/mevalffi.nim +++ b/tests/vm/mevalffi.nim @@ -1,7 +1,7 @@ # re-enable for windows once libffi can be installed in koch.nim # With win32 (not yet win64), libffi on windows works and this test passes. -when defined(linux) or defined(freebsd): +when defined(linux) or defined(bsd): {.passL: "-lm".} # for exp proc c_exp(a: float64): float64 {.importc: "exp", header: "".} From 6ca81184e969de2d9746a9374abe87f70f64f78a Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Tue, 4 Feb 2020 00:30:03 -0800 Subject: [PATCH 13/14] fix for CI --- tests/vm/tevalffi.nim | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/tests/vm/tevalffi.nim b/tests/vm/tevalffi.nim index 8306f01808259..90acdd18f064c 100644 --- a/tests/vm/tevalffi.nim +++ b/tests/vm/tevalffi.nim @@ -7,20 +7,11 @@ import std/[strformat,os,osproc] proc main() = const nim = getCurrentCompilerExe() const file = currentSourcePath().parentDir / "mevalffi.nim" - let cmd = fmt"{nim} c -r -f --experimental:compiletimeFFI --hints:off {file}" + let cmd = fmt"{nim} c -f --experimental:compiletimeFFI --hints:off {file}" let (output, exitCode) = execCmdEx(cmd) let expected = """ hello world stderr hi stderr -hello world stderr -hi stderr -foo -foo:100 -foo:101 -foo:102:103 -foo:102:103:104 -foo:0.03:asdf:103:105 -ret={s1:foobar s2:foobar age:25 pi:3.14} foo foo:100 foo:101 From 0b273f1ec0a7599a5f398ffa649364fd6a374d61 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Tue, 4 Feb 2020 01:28:24 -0800 Subject: [PATCH 14/14] fixup --- tests/vm/tevalffi.nim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/vm/tevalffi.nim b/tests/vm/tevalffi.nim index 90acdd18f064c..02374869ec099 100644 --- a/tests/vm/tevalffi.nim +++ b/tests/vm/tevalffi.nim @@ -7,7 +7,8 @@ import std/[strformat,os,osproc] proc main() = const nim = getCurrentCompilerExe() const file = currentSourcePath().parentDir / "mevalffi.nim" - let cmd = fmt"{nim} c -f --experimental:compiletimeFFI --hints:off {file}" + # strangely, --hint:cc:off was needed + let cmd = fmt"{nim} c -f --experimental:compiletimeFFI --hints:off --hint:cc:off {file}" let (output, exitCode) = execCmdEx(cmd) let expected = """ hello world stderr