From eca114efb0f62a7432bcafb466e27305c647ea59 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Thu, 16 Apr 2020 01:26:55 -0700 Subject: [PATCH 1/5] * fix regression: -d:nimHasLibFFI was not being tested anymore, in part because testament was silently treating some errors as easy to overlook messages * turned that message into an error * -d:nimHasLibFFI is now being tested with nim cpp * use correct signatures for importc procs --- koch.nim | 9 ++++++--- testament/categories.nim | 2 +- tests/trunner.nim | 11 +++++++---- tests/vm/mevalffi.nim | 13 ++++++++----- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/koch.nim b/koch.nim index 9193cb43edac1..017db86783770 100644 --- a/koch.nim +++ b/koch.nim @@ -289,11 +289,13 @@ proc findStartNim: string = proc thVersion(i: int): string = result = ("compiler" / "nim" & $i).exe +template doUseCpp(): bool = getEnv("NIM_COMPILE_TO_CPP", "false") == "true" + proc boot(args: string) = var output = "compiler" / "nim".exe var finalDest = "bin" / "nim".exe # default to use the 'c' command: - let useCpp = getEnv("NIM_COMPILE_TO_CPP", "false") == "true" + let useCpp = doUseCpp() let smartNimcache = (if "release" in args or "danger" in args: "nimcache/r_" else: "nimcache/d_") & hostOS & "_" & hostCPU @@ -542,8 +544,9 @@ proc runCI(cmd: string) = 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", "$1 c -r testament/testament --nim:$1 r tests/vm/tevalffi.nim" % [nimFFI]) + let backend = if doUseCpp(): "cpp" else: "c" + execFold("build with -d:nimHasLibFFI", "nim $1 -d:release -d:nimHasLibFFI -o:$2 compiler/nim.nim" % [backend, nimFFI]) + execFold("test with -d:nimHasLibFFI", "$1 $2 -r testament/testament --nim:$1 r tests/trunner.nim" % [nimFFI, backend]) execFold("Run nimdoc tests", "nim c -r nimdoc/tester") execFold("Run nimpretty tests", "nim c -r nimpretty/tester.nim") diff --git a/testament/categories.nim b/testament/categories.nim index e1519468fe25a..3affe0699a80f 100644 --- a/testament/categories.nim +++ b/testament/categories.nim @@ -545,7 +545,7 @@ proc processSingleTest(r: var TResults, cat: Category, options, test: string) = if existsFile(test): testSpec r, makeTest(test, options, cat), {target} else: - echo "[Warning] - ", test, " test does not exist" + doAssert false, test & " test does not exist" proc isJoinableSpec(spec: TSpec): bool = result = not spec.sortoutput and diff --git a/tests/trunner.nim b/tests/trunner.nim index 265a3712d4cff..86b256262cce1 100644 --- a/tests/trunner.nim +++ b/tests/trunner.nim @@ -1,4 +1,5 @@ discard """ + targets: "c cpp" joinable: false """ @@ -9,16 +10,18 @@ import std/[strformat,os,osproc,strutils] const nim = getCurrentCompilerExe() +const mode = + when defined(c): "c" + elif defined(cpp): "cpp" + else: static: doAssert false + proc runCmd(file, options = ""): auto = - let mode = if existsEnv("NIM_COMPILE_TO_CPP"): "cpp" else: "c" const testsDir = currentSourcePath().parentDir let fileabs = testsDir / file.unixToNativePath doAssert fileabs.existsFile, fileabs let cmd = fmt"{nim} {mode} {options} --hints:off {fileabs}" result = execCmdEx(cmd) - when false: # uncomment if you need to debug - echo result[0] - echo result[1] + when false: echo result[0] & "\n" & result[1] # for debugging when defined(nimHasLibFFIEnabled): block: # mevalffi diff --git a/tests/vm/mevalffi.nim b/tests/vm/mevalffi.nim index e15ed8f74dd09..cce4bc64e9592 100644 --- a/tests/vm/mevalffi.nim +++ b/tests/vm/mevalffi.nim @@ -8,9 +8,9 @@ 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_snprintf*(str: cstring, size: csize_t, format: cstring): cint {.importc: snprintfName, header: "", varargs .} -proc c_malloc(size:uint):pointer {.importc:"malloc", header: "".} +proc c_malloc(size: csize_t): pointer {.importc:"malloc", header: "".} proc c_free(p: pointer) {.importc:"free", header: "".} proc fun() = @@ -35,12 +35,15 @@ proc fun() = block: # c_snprintf, c_malloc, c_free let n: uint = 50 - var buffer2: pointer = c_malloc(n) + var buffer2 = cstring(cast[ptr char](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) + let num = c_snprintf(buffer2, n, "s1:%s s2:%s age:%d pi:%g", s, s, age, 3.14) + let numExp = 34 + doAssert num == numExp c_printf("ret={%s}\n", buffer2) - c_free(buffer2) # not sure it has an effect + c_free(buffer2) block: # c_printf bug var a = 123 From 7ec201c68449eaa0e08094d16cf26f7dd905de9e Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Tue, 5 May 2020 17:22:03 -0700 Subject: [PATCH 2/5] fix test --- lib/system/ansi_c.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/system/ansi_c.nim b/lib/system/ansi_c.nim index 0b4b259921222..510a840767da5 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) or defined(dragonfly)) and not defined(emscripten) +const stdioUsesMacros = (defined(osx) or defined(bsd) or defined(dragonfly)) 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" From 1049997fa51f193b2f133761dc24e6863eaba275 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Tue, 5 May 2020 17:56:29 -0700 Subject: [PATCH 3/5] _ --- .builds/openbsd.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.builds/openbsd.yml b/.builds/openbsd.yml index c4db2f6216bea..80be2113ad169 100644 --- a/.builds/openbsd.yml +++ b/.builds/openbsd.yml @@ -8,8 +8,8 @@ packages: - sfml - sdl2 - libffi -sources: -- https://github.com/nim-lang/Nim +#sources: +#- https://github.com/nim-lang/Nim environment: CC: /usr/bin/clang tasks: From bcaa62940893dbed21682ebb6f85286c472af8cc Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Tue, 5 May 2020 18:03:31 -0700 Subject: [PATCH 4/5] _ --- .builds/openbsd.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.builds/openbsd.yml b/.builds/openbsd.yml index 80be2113ad169..90380fa0446e1 100644 --- a/.builds/openbsd.yml +++ b/.builds/openbsd.yml @@ -1,5 +1,6 @@ image: openbsd/latest -packages: +image2: openbsd/latest + packages: - gmake - sqlite3 - node @@ -8,7 +9,14 @@ packages: - sfml - sdl2 - libffi -#sources: + +asdf +asdfasdf +sdf + + +sources: +- https://github.com/nim-lang/Nim #- https://github.com/nim-lang/Nim environment: CC: /usr/bin/clang @@ -26,6 +34,6 @@ tasks: exit 1 fi triggers: -- action: email +-- action: email condition: failure to: Andreas Rumpf From b7dae0b638e3bdae6f092909884b7d3604aaabc7 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Tue, 5 May 2020 18:04:10 -0700 Subject: [PATCH 5/5] _ --- .builds/freebsd.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.builds/freebsd.yml b/.builds/freebsd.yml index ef2e8f44d0715..7fe9c661eb199 100644 --- a/.builds/freebsd.yml +++ b/.builds/freebsd.yml @@ -1,5 +1,8 @@ # see https://man.sr.ht/builds.sr.ht/compatibility.md#freebsd image: freebsd/latest + image: freebsd/latest + +asdf # packages: # - databases/sqlite3 @@ -15,7 +18,7 @@ sources: environment: CC: /usr/bin/clang tasks: -- setup: | +-- setup: | # workaround https://github.com/timotheecour/Nim/issues/76 sudo pkg update -q -f sudo pkg install -y -q databases/sqlite3 devel/boehm-gc-threaded devel/pcre \