Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .builds/freebsd.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 \
Expand Down
12 changes: 10 additions & 2 deletions .builds/openbsd.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
image: openbsd/latest
packages:
image2: openbsd/latest
packages:
- gmake
- sqlite3
- node
Expand All @@ -8,8 +9,15 @@ packages:
- sfml
- sdl2
- libffi

asdf
asdfasdf
sdf


sources:
- https://github.com/nim-lang/Nim
#- https://github.com/nim-lang/Nim
environment:
CC: /usr/bin/clang
tasks:
Expand All @@ -26,6 +34,6 @@ tasks:
exit 1
fi
triggers:
- action: email
-- action: email
condition: failure
to: Andreas Rumpf <rumpf_a@web.de>
9 changes: 6 additions & 3 deletions koch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion lib/system/ansi_c.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion testament/categories.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions tests/trunner.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
discard """
targets: "c cpp"
joinable: false
"""

Expand All @@ -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
Expand Down
13 changes: 8 additions & 5 deletions tests/vm/mevalffi.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ proc c_exp(a: float64): float64 {.importc: "exp", header: "<math.h>".}
proc c_printf(frmt: cstring): cint {.importc: "printf", header: "<stdio.h>", varargs, discardable.}

const snprintfName = when defined(windows): "_snprintf" else: "snprintf"
proc c_snprintf*(buffer: pointer, buf_size: uint, format: cstring): cint {.importc: snprintfName, header: "<stdio.h>", varargs .}
proc c_snprintf*(str: cstring, size: csize_t, format: cstring): cint {.importc: snprintfName, header: "<stdio.h>", varargs .}

proc c_malloc(size:uint):pointer {.importc:"malloc", header: "<stdlib.h>".}
proc c_malloc(size: csize_t): pointer {.importc:"malloc", header: "<stdlib.h>".}
proc c_free(p: pointer) {.importc:"free", header: "<stdlib.h>".}

proc fun() =
Expand All @@ -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
Expand Down