Skip to content

Commit

Permalink
bring back std/ prefix within compiler and ensure it works in bootstr…
Browse files Browse the repository at this point in the history
…ap + bsd (nim-lang#17902)

* [WIP] bring back std/ prefix within compiler and ensure it works in bootstrap + bsd

* refs nim-lang#16282 (comment)
* sounds very similar to nim-lang#14291
* more: vmops
* update tools/ci_generate.nim
* auto-generate freebsd.yml as well, to avoid duplication with openbsd.yml
* cleanup
* undo temporary CI removal
  • Loading branch information
timotheecour authored Apr 30, 2021
1 parent d32ab61 commit d0485e3
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 33 deletions.
8 changes: 7 additions & 1 deletion .builds/freebsd.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## DO NO EDIT DIRECTLY! auto-generated by `nim r tools/ci_generate.nim`

# see https://man.sr.ht/builds.sr.ht/compatibility.md#freebsd
image: freebsd/latest
packages:
Expand All @@ -8,9 +10,12 @@ packages:
- devel/sfml
- www/node
- devel/gmake


sources:
- https://github.com/nim-lang/Nim
environment:
NIM_TESTAMENT_BATCH: "0_1"
CC: /usr/bin/clang
tasks:
- setup: |
Expand All @@ -20,9 +25,10 @@ tasks:
$nim_csources c --skipUserCfg --skipParentCfg koch
echo 'export PATH=$HOME/Nim/bin:$PATH' >> $HOME/.buildenv
- test: |
set -e
cd Nim
if ! ./koch runCI; then
nim c -r tools/ci_testresults.nim
nim r tools/ci_testresults.nim
exit 1
fi
triggers:
Expand Down
7 changes: 5 additions & 2 deletions .builds/openbsd_0.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## do not edit directly; auto-generated by `nim r tools/ci_generate.nim`
## DO NO EDIT DIRECTLY! auto-generated by `nim r tools/ci_generate.nim`

image: openbsd/latest
packages:
Expand All @@ -10,6 +10,8 @@ packages:
- sfml
- sdl2
- libffi


sources:
- https://github.com/nim-lang/Nim
environment:
Expand All @@ -20,9 +22,10 @@ tasks:
set -e
cd Nim
. ci/funs.sh && nimBuildCsourcesIfNeeded
$nim_csources c koch
$nim_csources c --skipUserCfg --skipParentCfg koch
echo 'export PATH=$HOME/Nim/bin:$PATH' >> $HOME/.buildenv
- test: |
set -e
cd Nim
if ! ./koch runCI; then
nim r tools/ci_testresults.nim
Expand Down
7 changes: 5 additions & 2 deletions .builds/openbsd_1.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## do not edit directly; auto-generated by `nim r tools/ci_generate.nim`
## DO NO EDIT DIRECTLY! auto-generated by `nim r tools/ci_generate.nim`

image: openbsd/latest
packages:
Expand All @@ -10,6 +10,8 @@ packages:
- sfml
- sdl2
- libffi


sources:
- https://github.com/nim-lang/Nim
environment:
Expand All @@ -20,9 +22,10 @@ tasks:
set -e
cd Nim
. ci/funs.sh && nimBuildCsourcesIfNeeded
$nim_csources c koch
$nim_csources c --skipUserCfg --skipParentCfg koch
echo 'export PATH=$HOME/Nim/bin:$PATH' >> $HOME/.buildenv
- test: |
set -e
cd Nim
if ! ./koch runCI; then
nim r tools/ci_testresults.nim
Expand Down
2 changes: 1 addition & 1 deletion compiler/ic/dce.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

## Dead code elimination (=DCE) for IC.

import intsets, tables
import std/[intsets, tables]
import ".." / [ast, options, lineinfos, types]

import packed_ast, ic, bitabs
Expand Down
16 changes: 8 additions & 8 deletions compiler/vmops.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@

# Unfortunately this cannot be a module yet:
#import vmdeps, vm
from math import sqrt, ln, log10, log2, exp, round, arccos, arcsin,
from std/math import sqrt, ln, log10, log2, exp, round, arccos, arcsin,
arctan, arctan2, cos, cosh, hypot, sinh, sin, tan, tanh, pow, trunc,
floor, ceil, `mod`, cbrt, arcsinh, arccosh, arctanh, erf, erfc, gamma,
lgamma

when declared(math.copySign):
from math import copySign
from std/math import copySign

when declared(math.signbit):
from math import signbit
from std/math import signbit

from os import getEnv, existsEnv, dirExists, fileExists, putEnv, walkDir,
from std/os import getEnv, existsEnv, dirExists, fileExists, putEnv, walkDir,
getAppFilename, raiseOSError, osLastError

from md5 import getMD5
from times import cpuTime
from hashes import hash
from osproc import nil
from std/md5 import getMD5
from std/times import cpuTime
from std/hashes import hash
from std/osproc import nil

from sighashes import symBodyDigest

Expand Down
4 changes: 3 additions & 1 deletion koch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,9 @@ proc runCI(cmd: string) =
echo "runCI: ", cmd
echo hostInfo()
# boot without -d:nimHasLibFFI to make sure this still works
kochExecFold("Boot in release mode", "boot -d:release -d:nimStrictMode")
# `--lib:lib` is needed for bootstrap on openbsd, for reasons described in
# https://github.com/nim-lang/Nim/pull/14291 (`getAppFilename` bugsfor older nim on openbsd).
kochExecFold("Boot in release mode", "boot -d:release -d:nimStrictMode --lib:lib")

when false: # debugging: when you need to run only 1 test in CI, use something like this:
execFold("debugging test", "nim r tests/stdlib/tosproc.nim")
Expand Down
54 changes: 36 additions & 18 deletions tools/ci_generate.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
##[
avoid code duplication in CI pipelines.
For now, this is only used for openbsd, but there is a lot of other code
For now, this is only used for openbsd + freebsd, but there is a lot of other code
duplication that could be removed.
## usage
Expand All @@ -10,22 +10,14 @@ nim r tools/ci_generate.nim
```
]##

import std/strformat
import std/[strformat, os]

proc genCIopenbsd(batch: int, num: int): string =
proc genCiBsd(header: string, batch: int, num: int): string =
result = fmt"""
## do not edit directly; auto-generated by `nim r tools/ci_generate.nim`
## DO NO EDIT DIRECTLY! auto-generated by `nim r tools/ci_generate.nim`
{header}
image: openbsd/latest
packages:
- gmake
- sqlite3
- node
- boehm-gc
- pcre
- sfml
- sdl2
- libffi
sources:
- https://github.com/nim-lang/Nim
environment:
Expand All @@ -36,9 +28,10 @@ tasks:
set -e
cd Nim
. ci/funs.sh && nimBuildCsourcesIfNeeded
$nim_csources c koch
$nim_csources c --skipUserCfg --skipParentCfg koch
echo 'export PATH=$HOME/Nim/bin:$PATH' >> $HOME/.buildenv
- test: |
set -e
cd Nim
if ! ./koch runCI; then
nim r tools/ci_testresults.nim
Expand All @@ -51,14 +44,39 @@ triggers:
"""

proc main()=
let dir = ".builds"
# not too large to be resource friendly, refs bug #17107
let num = 2
# if you reduce this, make sure to remove files that shouldn't be generated,
# or better, do the cleanup logic here e.g.: `rm .builds/openbsd_*`
let headerFreebsd = """
# see https://man.sr.ht/builds.sr.ht/compatibility.md#freebsd
image: freebsd/latest
packages:
- databases/sqlite3
- devel/boehm-gc-threaded
- devel/pcre
- devel/sdl20
- devel/sfml
- www/node
- devel/gmake
"""

let headerOpenbsd = """
image: openbsd/latest
packages:
- gmake
- sqlite3
- node
- boehm-gc
- pcre
- sfml
- sdl2
- libffi
"""
for i in 0..<num:
let file = fmt".builds/openbsd_{i}.yml"
let code = genCIopenbsd(i, num)
writeFile(file, code)
writeFile(dir / fmt"openbsd_{i}.yml", genCiBsd(headerOpenbsd, i, num))
writeFile(dir / "freebsd.yml", genCiBsd(headerFreebsd, 0, 1))

when isMainModule:
main()

0 comments on commit d0485e3

Please sign in to comment.