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

switch("cpu", "i386") with --cc:vcc doesn't work when it is written on *.nims #10387

Closed
demotomohiro opened this issue Jan 20, 2019 · 2 comments

Comments

Projects
None yet
3 participants
@demotomohiro
Copy link
Contributor

commented Jan 20, 2019

switch("cpu", "i386") with --cc:vcc doesn't work when it is written on *.nims

When I set --cpu:i386 option on nims file, vccexe.exe is called with --platform:amd64 option from Nim and I got following compile error.
It looks like Nim compiler trying to build 32bit executable but passing wrong option (it should be --platform:x86) to vccexe.exe
When I set --cc:vcc --cpu:i386 option on command line, vccexe.exe is called with --platform:x86 option and Nim compiler works without errors.

Spec:
Nim: Build from git clone with PR #10383 merged.
OS: Windows 8.1
Backend: Visual Studio 2015

testvcc.nim:

echo sizeof(pointer)

testvcc.nims

switch("cpu", "i386")

Log:

f:\project\demotomohiro\testvcc>..\Nim\bin\nim.exe c --cc:vcc --listcmd -r testvcc.nim
Hint: used config file 'f:\project\demotomohiro\Nim\config\nim.cfg' [Conf]
Hint: used config file 'f:\project\demotomohiro\Nim\config\config.nims' [Conf]
Hint: system [Processing]
Hint: testvcc [Processing]
vccexe.exe /c --platform:amd64 /nologo  /If:\project\demotomohiro\Nim\lib /If:\project\demotomohiro\testvcc /Fof:\temp\nimcach
e\testvcc\debug\stdlib_system.c.obj f:\temp\nimcache\testvcc\debug\stdlib_system.c
vccexe.exe /c --platform:amd64 /nologo  /If:\project\demotomohiro\Nim\lib /If:\project\demotomohiro\testvcc /Fof:\temp\nimcach
e\testvcc\debug\testvcc.c.obj f:\temp\nimcache\testvcc\debug\testvcc.c
Error: execution of an external compiler program 'vccexe.exe /c --platform:amd64 /nologo  /If:\project\demotomohiro\Nim\lib /I
f:\project\demotomohiro\testvcc /Fof:\temp\nimcache\testvcc\debug\testvcc.c.obj f:\temp\nimcache\testvcc\debug\testvcc.c' fail
ed with exit code: 2

testvcc.c
f:\project\demotomohiro\Nim\lib\nimbase.h(490): error C2118: 添字が負の数です。(Index is negative value) ..\lib\system.nim(3016)  sysFatal
Error: unhandled exception: errno: 2 `No such file or directory` [IOError]

Log (add --cpu:i386 to command line option):

f:\project\demotomohiro\testvcc>..\Nim\bin\nim.exe c --cc:vcc --cpu:i386 --listcmd -r testvcc.nim
Hint: used config file 'f:\project\demotomohiro\Nim\config\nim.cfg' [Conf]
Hint: used config file 'f:\project\demotomohiro\Nim\config\config.nims' [Conf]
Hint: system [Processing]
Hint: testvcc [Processing]
vccexe.exe /c --platform:x86 /nologo  /If:\project\demotomohiro\Nim\lib /If:\project\demotomohiro\testvcc /Fof:\temp\nimcache\
testvcc\debug\stdlib_system.c.obj f:\temp\nimcache\testvcc\debug\stdlib_system.c
vccexe.exe /c --platform:x86 /nologo  /If:\project\demotomohiro\Nim\lib /If:\project\demotomohiro\testvcc /Fof:\temp\nimcache\
testvcc\debug\testvcc.c.obj f:\temp\nimcache\testvcc\debug\testvcc.c
Hint: vccexe.exe    --platform:x86 /nologo /DEBUG /Zi /F33554432  /Fef:\project\demotomohiro\testvcc\testvcc.exe  f:\temp\nimc
ache\testvcc\debug\stdlib_system.c.obj f:\temp\nimcache\testvcc\debug\testvcc.c.obj  [Exec]
Hint: operation successful (24038 lines compiled; 9.834 sec total; 25.129MiB peakmem; Debug Build) [SuccessX]
Hint: f:\project\demotomohiro\testvcc\testvcc.exe  [Exec]
4
@demotomohiro

This comment has been minimized.

Copy link
Contributor Author

commented Feb 25, 2019

loadConfigsAndRunMainCommand procedure in compiler/cmdlinehelper.nim run nim script file after loading config files.
cpu or os switch set on nim script doesn't affect @if CPU/OS branch in config/nim.cfg.
I think i386.windows.vcc.* options need to be added on config/nim.cfg, because compiling 32bit executable (cpu:i386) on 64bit windows is cross compilation.

cpu or os switches cannot be set on *.nims file bug might exist on other platform.
I don't have nintendo switch SDK but when I set os:nintendoswitch on test.nims file, I got different error that I got when I set that switch on command line.

Output when I add --os:nintendoswitch on commad line:

f:\temp>nim c --listcmd --os:nintendoswitch test.nim
Hint: used config file 'f:\project\nim-lang\Nim\config\nim.cfg' [Conf]
Hint: used config file 'f:\project\nim-lang\Nim\config\config.nims' [Conf]
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: test [Processing]
cannot create directory: \tmp\nimcache\test\debug

test.nims:

switch("os", "nintendoswitch")

Output when I set os:nintendoswitch on test.nims:
(switch_gcc.options.always set on config/nim.cfg is not used)

f:\temp>nim c --listcmd test.nim
Hint: used config file 'f:\project\nim-lang\Nim\config\nim.cfg' [Conf]
Hint: used config file 'f:\project\nim-lang\Nim\config\config.nims' [Conf]
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: test [Processing]
gcc.exe -c  -w -mno-ms-bitfields  -If:\project\nim-lang\Nim\lib -If:\temp -o f:\temp\nimcache\test\debug\stdlib_indexerrors.c
.o f:\temp\nimcache\test\debug\stdlib_indexerrors.c
gcc.exe -c  -w -mno-ms-bitfields  -If:\project\nim-lang\Nim\lib -If:\temp -o f:\temp\nimcache\test\debug\stdlib_switch_memory
.c.o f:\temp\nimcache\test\debug\stdlib_switch_memory.c
gcc.exe -c  -w -mno-ms-bitfields  -If:\project\nim-lang\Nim\lib -If:\temp -o f:\temp\nimcache\test\debug\stdlib_widestrs.c.o
f:\temp\nimcache\test\debug\stdlib_widestrs.c
gcc.exe -c  -w -mno-ms-bitfields  -If:\project\nim-lang\Nim\lib -If:\temp -o f:\temp\nimcache\test\debug\stdlib_io.c.o f:\tem
p\nimcache\test\debug\stdlib_io.c
gcc.exe -c  -w -mno-ms-bitfields  -If:\project\nim-lang\Nim\lib -If:\temp -o f:\temp\nimcache\test\debug\stdlib_system.c.o f:
\temp\nimcache\test\debug\stdlib_system.c
gcc.exe -c  -w -mno-ms-bitfields  -If:\project\nim-lang\Nim\lib -If:\temp -o f:\temp\nimcache\test\debug\test.c.o f:\temp\nim
cache\test\debug\test.c
Error: execution of an external compiler program 'gcc.exe -c  -w -mno-ms-bitfields  -If:\project\nim-lang\Nim\lib -If:\temp -
o f:\temp\nimcache\test\debug\stdlib_system.c.o f:\temp\nimcache\test\debug\stdlib_system.c' failed with exit code: 1

f:\temp\nimcache\test\debug\stdlib_system.c:15:10: fatal error: switch/kernel/virtmem.h: No such file or directory
 #include <switch/kernel/virtmem.h>
          ^~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
@demotomohiro

This comment has been minimized.

Copy link
Contributor Author

commented Feb 25, 2019

I guess cross compilation configuration in config/nim.cfg must be set with $cpu.$os.$cc.* = "options" format and must not use @if branch to specify targetOS or targetCPU.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.