On Wed, Mar 01, 2017 at 05:45:32PM +0000, Stuart Henderson wrote:
> On 2017/03/01 17:10, Juan Francisco Cantero Hurtado wrote:
> > On Tue, Feb 28, 2017 at 07:11:48PM +0100, Juan Francisco Cantero Hurtado 
> > wrote:
> > > On Tue, Feb 28, 2017 at 01:03:38PM +0000, Christian Weisgerber wrote:
> > > > The fixes that have been committed have unlocked additional parts
> > > > of the ports tree, revealing new build failures.  Here is an updated
> > > > list.  I've added the MAINTAINERs.
> > > > 
> > > > lang/nim            The OpenBSD ports mailing-list <ports@openbsd.org>
> > > 
> > > I've a patch for nim from two or three days ago. It builds the package
> > > but I don't find where is the gcc command in the tests and I don't want
> > > commit the changes without to run first the tests.
> > 
> > Everything is working now but I need help with something. Nim uses a
> > kind of compiler profiles, so we can't just add "${CC}" to the build, we
> > need to define the real compiler, i.e. gcc, egcc or clang. Now I'm using
> > an if/else conditional with MACHINE_ARCH to define the compiler but I
> > would like to use something like "if CLANG_ARCHS contains
> > MACHINE_ARCH...". I don't know how to write that. Any idea?.
> > 
> > -- 
> > Juan Francisco Cantero Hurtado http://juanfra.info
> > 
> 
> Ports should honour CC/CXX. Can you sed these into wherever the
> compiler profile is defined?

No, because ${CC} is always "cc", not "gcc" or "clang".

We can't use a regex blindly to modify nim because it will give us
problems. Patching the code is even worse because the updates will be
harder and nim hasn't a maintainer.

They have a simple option to change the compilers but we need a variable
with the realname of the compiler, i.e. clang or gcc.

You can use "nim c -cc:clang" or "nim c -cc:gcc" (the default) or "nim c
-cc:egcc". All of them are the name of the profile, not the compiler
executable.

Here is the patch. It includes some adittional changes. If someone has
an better idea for the conditional... I'm listening :)


Index: Makefile
===================================================================
RCS file: /cvs/ports/lang/nim/Makefile,v
retrieving revision 1.6
diff -u -p -r1.6 Makefile
--- Makefile    9 Jan 2017 10:32:33 -0000       1.6
+++ Makefile    1 Mar 2017 19:55:21 -0000
@@ -5,6 +5,7 @@ ONLY_FOR_ARCHS =        i386 amd64
 COMMENT =              statically typed, imperative programming language
 
 VERSION =              0.16.0
+REVISION =             0
 DISTNAME =             nim-${VERSION}
 EXTRACT_SUFX =         .tar.xz
 
@@ -19,23 +20,28 @@ PERMIT_PACKAGE_CDROM =      Yes
 
 WANTLIB =              c m
 
+SUBST_VARS +=          CC
+
 post-patch:
        mkdir -p ${WRKSRC}/nimcache-port
        mkdir -p ${WRKSRC}/nimcache-port-test
        perl -i -pe "s#NIM_PORT_PATH#${PATH}#" ${WRKSRC}/koch.nim
        perl -i -pe "s#NIM_PORT_CACHE#${WRKSRC}/nimcache-port-test#" \
                ${WRKSRC}/koch.nim
+       ${SUBST_CMD} ${WRKSRC}/koch.nim ${WRKSRC}/tests/testament/tester.nim \
+               ${WRKSRC}/config/nim.cfg
 
 do-build:
        cd ${WRKSRC} && ${SETENV} CC="${CC}" LINKER="${CC}" \
                CFLAGS="${CFLAGS}" sh build.sh
        # slow machines can get a head of themselves and fail to link
-       cd ${WRKSRC} && bin/nim c -d:release --parallelBuild:1 \
-               --nimcache:"${WRKSRC}/nimcache-port" --listFullPaths \
-               --listCmd --putenv:"PATH=${PATH}" koch
-       cd ${WRKSRC} && ./koch boot -d:release --parallelBuild:1 \
-               --nimcache:"${WRKSRC}/nimcache-port" --listFullPaths \
-               --listCmd --putenv:"PATH=${PATH}"
+       cd ${WRKSRC} && bin/nim c -d:release --cc:${CC} --parallelBuild:1 \
+               --nimcache:"${WRKSRC}/nimcache-port" --listFullPaths --listCmd \
+               --putenv:"PATH=${PATH} CC=${CC} LINKER=${CC}" \
+               koch
+       cd ${WRKSRC} && ./koch boot -d:release --cc:${CC} --parallelBuild:1 \
+               --nimcache:"${WRKSRC}/nimcache-port" --listFullPaths --listCmd \
+               --putenv:"PATH=${PATH} CC=${CC} LINKER=${CC}"
 
 do-install:
        ${INSTALL_PROGRAM_DIR} ${PREFIX}/bin
@@ -49,9 +55,16 @@ do-install:
        ${INSTALL_DATA} ${WRKSRC}/config/*.cfg ${PREFIX}/share/examples/nim
 
 do-test:
-       cd ${WRKSRC} && ${SETENV} ./koch test all -d:release \
-               --parallelBuild:1 --listFullPaths --listCmd \
-               --nimcache:"${WRKSRC}/nimcache-port-test" \
-               --putenv:"PATH=${PATH}"
+       cd ${WRKSRC} && ${SETENV} ./koch test all -d:release --threads:on \
+               --cc:${CC} --parallelBuild:1 --listFullPaths --listCmd \
+               --passL:"-pthread 
-Wl,-rpath=.:/usr/local/lib:${WRKSRC}/nimcache-port-test/" \
+               --putenv:"PATH=${PATH} CC=${CC} LINKER=${CC}"
+
+# CC is always "cc". We need the real name.
+.if ${MACHINE_ARCH} == "amd64"
+CC = clang
+.elif
+CC = gcc
+.endif
 
 .include <bsd.port.mk>
Index: patches/patch-config_nim_cfg
===================================================================
RCS file: /cvs/ports/lang/nim/patches/patch-config_nim_cfg,v
retrieving revision 1.3
diff -u -p -r1.3 patch-config_nim_cfg
--- patches/patch-config_nim_cfg        9 Jan 2017 10:32:33 -0000       1.3
+++ patches/patch-config_nim_cfg        1 Mar 2017 19:55:21 -0000
@@ -1,6 +1,15 @@
 $OpenBSD: patch-config_nim_cfg,v 1.3 2017/01/09 10:32:33 juanfra Exp $
 --- config/nim.cfg.orig        Sun Jan  8 21:33:42 2017
-+++ config/nim.cfg     Mon Jan  9 02:28:32 2017
++++ config/nim.cfg     Wed Mar  1 00:00:37 2017
+@@ -8,7 +8,7 @@
+ # Environment variables can be accessed like so:
+ #  gcc.path %= "$CC_PATH"
+ 
+-cc = gcc
++cc = ${CC}
+ 
+ # additional options always passed to the compiler:
+ --parallel_build: "0" # 0 to auto-detect number of processors
 @@ -76,7 +76,7 @@ path="$lib/pure"
    @end
    @if bsd or haiku:
@@ -19,7 +28,16 @@ $OpenBSD: patch-config_nim_cfg,v 1.3 201
  @end
  
  # Configuration for Objective-C compiler:
-@@ -155,18 +157,23 @@ clang.objc.options.linker = "-lobjc -lgnustep-base"
+@@ -135,6 +137,8 @@ clang.objc.options.linker = "-lobjc -lgnustep-base"
+ @if freebsd or openbsd or netbsd:
+   gcc.options.linker = 
"-Wl,-rpath=.:/usr/local/lib:/usr/pkg/lib:/usr/X11R6/lib"
+   gcc.cpp.options.linker = 
"-Wl,-rpath=.:/usr/local/lib:/usr/pkg/lib:/usr/X11R6/lib"
++  egcc.options.linker = 
"-Wl,-rpath=.:/usr/local/lib:/usr/pkg/lib:/usr/X11R6/lib"
++  egcc.cpp.options.linker = 
"-Wl,-rpath=.:/usr/local/lib:/usr/pkg/lib:/usr/X11R6/lib"
+   llvm_gcc.options.linker = 
"-Wl,-rpath=.:/usr/local/lib:/usr/pkg/lib:/usr/X11R6/lib"
+   llvm_gcc.cpp.options.linker = 
"-Wl,-rpath=.:/usr/local/lib:/usr/pkg/lib:/usr/X11R6/lib"
+   clang.options.linker = 
"-Wl,-rpath=.:/usr/local/lib:/usr/pkg/lib:/usr/X11R6/lib"
+@@ -155,18 +159,23 @@ clang.objc.options.linker = "-lobjc -lgnustep-base"
    gcc.options.linker %= "-L $WIND_BASE/target/lib/usr/lib/ppc/PPC32/common 
-mrtp -fno-strict-aliasing -D_C99 -D_HAS_C9X -std=c99 -fasm -Wall 
-Wno-write-strings"
  @end
  
@@ -45,7 +63,7 @@ $OpenBSD: patch-config_nim_cfg,v 1.3 201
  # Configuration for the LLVM GCC compiler:
  llvm_gcc.options.debug = "-g"
  llvm_gcc.options.always = "-w"
-@@ -176,7 +183,7 @@ llvm_gcc.options.size = "-Os"
+@@ -176,7 +185,7 @@ llvm_gcc.options.size = "-Os"
  # Configuration for the LLVM CLang compiler:
  clang.options.debug = "-g"
  clang.options.always = "-w"
Index: patches/patch-koch_nim
===================================================================
RCS file: /cvs/ports/lang/nim/patches/patch-koch_nim,v
retrieving revision 1.2
diff -u -p -r1.2 patch-koch_nim
--- patches/patch-koch_nim      9 Jan 2017 10:32:33 -0000       1.2
+++ patches/patch-koch_nim      1 Mar 2017 19:55:21 -0000
@@ -1,12 +1,19 @@
 $OpenBSD: patch-koch_nim,v 1.2 2017/01/09 10:32:33 juanfra Exp $
 --- koch.nim.orig      Sun Jan  8 21:33:42 2017
-+++ koch.nim   Mon Jan  9 03:15:50 2017
-@@ -393,7 +393,7 @@ proc tests(args: string) =
-   nimexec "cc --taintMode:on tests/testament/tester"
++++ koch.nim   Tue Feb 28 23:20:42 2017
+@@ -390,12 +390,12 @@ template `|`(a, b): string = (if a.len > 0: a else: b)
+ proc tests(args: string) =
+   # we compile the tester with taintMode:on to have a basic
+   # taint mode test :-)
+-  nimexec "cc --taintMode:on tests/testament/tester"
++  nimexec "cc --taintMode:on --cc:${CC} tests/testament/tester"
    # Since tests take a long time (on my machine), and we want to defy Murhpys
    # law - lets make sure the compiler really is freshly compiled!
 -  nimexec "c --lib:lib -d:release --opt:speed compiler/nim.nim"
-+  nimexec "c --lib:lib -d:release --opt:speed --listFullPaths --listCmd 
--putenv:PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin::
 --nimcache:/usr/write-ports/pobj/nim-0.16.0/nim-0.16.0/nimcache-port-test 
compiler/nim.nim"
++  nimexec "c --lib:lib -d:release --cc:${CC} --opt:speed --listFullPaths 
--listCmd 
--putenv:PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin::
 --nimcache:/usr/write-ports/pobj/nim-0.16.0/nim-0.16.0/nimcache-port-test 
compiler/nim.nim"
    let tester = quoteShell(getCurrentDir() / "tests/testament/tester".exe)
-   let success = tryExec tester & " " & (args|"all")
+-  let success = tryExec tester & " " & (args|"all")
++  let success = tryExec tester & " --targets:c " & " " & (args|"all")
    if not existsEnv("TRAVIS") and not existsEnv("APPVEYOR"):
+     exec tester & " html"
+   if not success:
Index: patches/patch-tests_testament_tester_nim
===================================================================
RCS file: /cvs/ports/lang/nim/patches/patch-tests_testament_tester_nim,v
retrieving revision 1.3
diff -u -p -r1.3 patch-tests_testament_tester_nim
--- patches/patch-tests_testament_tester_nim    9 Jan 2017 10:32:33 -0000       
1.3
+++ patches/patch-tests_testament_tester_nim    1 Mar 2017 19:55:21 -0000
@@ -8,7 +8,7 @@ FAILURE
 Error 1 in . (Makefile:42 'do-test')"
 
 --- tests/testament/tester.nim.orig    Sun Jan  8 21:33:43 2017
-+++ tests/testament/tester.nim Mon Jan  9 02:33:36 2017
++++ tests/testament/tester.nim Tue Feb 28 23:20:42 2017
 @@ -12,7 +12,7 @@
  import
    parseutils, strutils, pegs, os, osproc, streams, parsecfg, json,
@@ -18,6 +18,15 @@ Error 1 in . (Makefile:42 'do-test')"
  
  const
    resultsFile = "testresults.html"
+@@ -118,7 +118,7 @@ proc callCCompiler(cmdTemplate, filename, options: str
+                   target: TTarget): TSpec =
+   let c = parseCmdLine(cmdTemplate % ["target", targetToCmd[target],
+                        "options", options, "file", filename.quoteShell])
+-  var p = startProcess(command="gcc", args=c[5.. ^1],
++  var p = startProcess(command="${CC}", args=c[5.. ^1],
+                        options={poStdErrToStdOut, poUsePath})
+   let outp = p.outputStream
+   var x = newStringOfCap(120)
 @@ -326,7 +326,7 @@ proc testSpec(r: var TResults, test: TTest) =
        r.addResult(test, expected.outp, "executable not found", reExeNotFound)
        return

Reply via email to