Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nimrod 0.9.6 OSX codegen error in release builds #1701

Closed
gradha opened this issue Dec 3, 2014 · 3 comments
Closed

Nimrod 0.9.6 OSX codegen error in release builds #1701

gradha opened this issue Dec 3, 2014 · 3 comments

Comments

@gradha
Copy link
Contributor

gradha commented Dec 3, 2014

While looking at nim-lang/nimble#62 I started bisecting the code and quickly found that the compiler generates bad C code with -d:release for certain programs on OSX. This can be verified using the zip for 0.9.6 running the following commands:

$ sh build.sh
$ bin/nimrod c -d:release --parallelBuild:1 koch
config/nimrod.cfg(38, 2) Hint: added path: '/Users/gradha/.babel/pkgs/' [Path]
Hint: used config file '/private/tmp/distri/nimrod/config/nimrod.cfg' [Conf]
Hint: system [Processing]
Hint: koch [Processing]
Hint: os [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: times [Processing]
Hint: posix [Processing]
Hint: parseopt [Processing]
lib/pure/parseopt.nim(54, 34) Warning: 'quoteIfContainsWhite' is deprecated [Deprecated]
koch.nim(19, 16) Warning: 'parseopt' is deprecated [Deprecated]
Hint: osproc [Processing]
Hint: strtabs [Processing]
Hint: hashes [Processing]
Hint: streams [Processing]
Hint: cpuinfo [Processing]
lib/pure/osproc.nim(250, 13) Warning: 'startCmd' is deprecated [Deprecated]
lib/pure/osproc.nim(274, 19) Warning: 'startCmd' is deprecated [Deprecated]
lib/pure/osproc.nim(282, 14) Warning: 'startCmd' is deprecated [Deprecated]
lib/pure/osproc.nim(756, 6) Warning: 'osError' is deprecated [Deprecated]
lib/pure/osproc.nim(922, 10) Warning: 'startCmd' is deprecated [Deprecated]
lib/pure/osproc.nim(724, 7) Hint: 'osproc.startProcessAuxFork(data: TStartProcessData): TPid' is declared but not used [XDeclaredButNotUsed]
koch.nim(21, 12) Warning: undeclared conditional symbol; use --symbol to declare it: withUpdate [User]
koch.nim(23, 12) Warning: undeclared conditional symbol; use --symbol to declare it: haveZipLib [User]
koch.nim(186, 11) Hint: 'dir' is declared but not used [XDeclaredButNotUsed]
koch.nim(217, 12) Warning: undeclared conditional symbol; use --symbol to declare it: withUpdate [User]
koch.nim(314, 16) Warning: undeclared conditional symbol; use --symbol to declare it: withUpdate [User]
nimcache/cpuinfo.c:10:1: error: extraneous closing brace ('}')
}
^
1 error generated.
Error: execution of an external program failed

The most simple example which I could reduce to find the problem is:

import osproc
echo "Hey"

Unfortunately compiling cpuinfo.nim alone doesn't fail compilation. However I did find out that the following patch fixes the problem:

diff --git a/lib/pure/concurrency/cpuinfo.nim b/lib/pure/concurrency/cpuinfo.nim
index 8d7f28f..7b0f120 100644
--- a/lib/pure/concurrency/cpuinfo.nim
+++ b/lib/pure/concurrency/cpuinfo.nim
@@ -28,7 +28,7 @@ when defined(openbsd) or defined(netbsd):
 when defined(macosx) or defined(bsd):
   # we HAVE to emit param.h before sysctl.h so we cannot use .header here
   # either. The amount of archaic bullshit in Poonix based OSes is just insane.
-  {.emit:"#include <sys/sysctl.h>".}
+  {.emit:"#include <sys/sysctl.h>\n".}
   const
     CTL_HW = 6
     HW_AVAILCPU = 25

The nim compiler doesn't have these problems and compiles nimble and other code fine in release mode. I'm not submitting this as a patch, if the emit was the problem it would also fail compilation of the lone cpuinfo.nim, yet that works, so I suspect the problem is elsewhere. For reference, here are the generated C files in different modes:

tl;dr, whatever source imports osproc won't compile on OSX with unpatched 0.9.6.

@Araq
Copy link
Member

Araq commented Dec 3, 2014

Emit now produces the newline but it's quite possible this didn't make it into 0.9.6.

@philip-wernersbach
Copy link
Contributor

May I suggest putting out an official 0.9.6.1 release that includes the newline changes to emit? We have to apply a workaround patch for Homebrew/legacy-homebrew#34693, and I really don't want to push out a development version of Nimrod over Homebrew.

@philip-wernersbach
Copy link
Contributor

For anyone reading this for help, this is fixed in HEAD but present in 0.9.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants