Commit Graph

261 Commits

Author SHA1 Message Date
metagn
449106a5a4 use /link before each library linker option on MSVC (#24291)
fixes #24087, refs https://forum.nim-lang.org/t/341, refs #14222, refs
#14221

The Nim compiler calls `cl` for linking as well as compilation. This
means that options to the linker have to be passed after a `/link`
argument. But the Nim compiler doesn't include this option normally,
because users may still want to pass non-linker options to `cl` at link
time.

To deal with this, a workaround is used: every single library link
option adds `/link` before it. The linker simply ignores extraneous
`/link` arguments and gives a warning instead, since it's an
unrecognized option to the linker. This is really hacky but otherwise we
need to separate linker arguments into arguments passed either to the
compiler or to the linker at link time, and this behavior wouldn't be
meaningful outside of MSVC.

I can't really test this manually but I did test that the linker ignores
`/link`. I also can't really do more than this, I don't really use MSVC
so I wouldn't know how to navigate it, or how people use it. Ideally
someone who knows more about/uses MSVC can give their input or take
over.
2024-10-12 21:17:30 +02:00
ringabout
95a7695810 documentation and comments use HTTPS when possible (#24264) 2024-10-08 21:50:35 +02:00
ringabout
0e1df88f7e check fileExists for outputFile (#24211)
ref
a5f46a72ba (commitcomment-147402726)
2024-10-01 08:11:07 +02:00
ringabout
4974baf7fa fixes #24008; triggers a recompilation on output executables changes when switching release/debug modes (#24193)
fixes #24008

The old logic didn't check the contents of the output executables, when
it switched release->debug->release, it picked up the Json files used in
the first release building, the content of which didn't change. So it
mistook the executables which are built by the second debug building as
the functioning one.

`changeDetectedViaJsonBuildInstructions` needs a way to distinguish the
executables generated by different buildings.
2024-09-30 20:55:47 +02:00
ringabout
732f7752a9 remove nir; succeeded by nif (#23809)
ref https://github.com/nim-lang/nif
2024-07-09 09:29:45 +02:00
Andrew Brower
dc46350fa1 Add support for nvcc & hipcc (cuda/rocm) (#23805)
I've been working on making some basic cuda examples work, both with
cuda (nvcc) and with AMD HIP (hipcc) https://github.com/monofuel/hippo

- hipcc is just a drop-in replacement for clang and works out of the box
with clang settings in Nim. hipcc is capable of compiling for AMD ROCm
or to CUDA, depending on how HIP_PLATFORM is set.
- nvcc is a little quirky. we can use `-x cu` to tell it to handle nim's
`.cpp` files as if they were `.cu` files. nvcc expects all backend
compiler flags to be wrapped with a special `-Xcompiler=""` flag when
compiling and also when linking.

I manually tested on a linux desktop with amd and a laptop with nvidia.
2024-07-08 11:17:04 +02:00
ringabout
519d976f62 compute checksum of nim files early in the pipelines (#23268)
related https://github.com/nim-lang/Nim/issues/21717 configs will be
resolved later
2024-01-31 21:36:59 +01:00
Andreas Rumpf
10c3ab6269 NIR: store sizes, alignments and offsets in the type graph; beginning… (#22822)
…s of a patent-pending new VM
2023-10-16 00:01:33 +02:00
ringabout
a1b6fa9420 fixes #22246; generate __builtin_unreachable hints for case defaults (#22737)
fixes #22246
resurrects #22350
2023-09-21 19:47:29 +02:00
ringabout
93ced31353 use strictdefs for compiler (#22365)
* wip; use strictdefs for compiler

* checkpoint

* complete the chores

* more fixes

* first phase cleanup

* Update compiler/bitsets.nim

* cleanup
2023-08-06 14:26:21 +02:00
ringabout
0b3ddd4e47 Revert "fixes #22246; generate __builtin_unreachable hints for case defaults" (#22351)
Revert "fixes #22246; generate `__builtin_unreachable` hints for case defaults (#22350)"

This reverts commit b56df5c07f.
2023-07-31 22:14:15 +08:00
ringabout
b56df5c07f fixes #22246; generate __builtin_unreachable hints for case defaults (#22350)
* fixes #22246; generate `__builtin_unreachable` hints

* use elif

* indentation

* fixes holy enums in sim
2023-07-31 16:02:52 +02:00
Anna
14a9929464 Fix #22281 (#22289)
Respect `--gcc.exe` and similar options when `--genScript:on` is used.
2023-07-18 16:06:21 +02:00
Etan Kissling
c6c85f84db macOS ar doesn't support @ syntax (#22146)
When the linker command line is long, Nim compiler generates a file for
passing the linker arguments. On `macOS`, that mechanism fails as the
`@` syntax is not supported by `ar`. Use `xargs` instead to pass the
linker arguments file.
2023-06-24 08:13:43 +02:00
ringabout
afc30ca879 fixes #19863; move sha1, md5 to nimble packages for 2.0 (#21702)
* move sha1, md5 to nimble packages

* boot the compiler

* fixes tests

* build the documentation

* fixes docs

* lol, I forgot koch.nim

* add `nimHasChecksums` define

* clone checksums but maybe copying is better

* bump nimble hash

* use ChecksumsStableCommit

* fixes tests

* deprecate them

* fixes paths

* fixes koch
2023-05-02 10:49:17 +02:00
Francis Thérien
7dc80a7fef Mitigate issues related to compiler options when cross-compiling (#21330)
* Document C compiler options config when cross-compiling

* Allow empty string to override default
2023-02-22 21:10:02 +01:00
Matt Haggard
6b93db7070 Fix long link commands on macOS (v2) (#21382)
Handle long link commands on macOS with a script, since ar does not support response files
2023-02-17 11:25:15 +01:00
rockcavera
9efa56a8bb [backport: 2.0] prevents the jsonscript command from exceeding the maximum length of a command line during linking (#21186) 2022-12-28 10:40:17 +08:00
ringabout
91ce8c385d fix #19580; add warning for bare except: clause (#21099)
* fix #19580; add warning for bare except: clause

* fixes some easy ones

* Update doc/manual.md

* fixes docs

* Update changelog.md

* addition

* Apply suggestions from code review

Co-authored-by: Jacek Sieka <arnetheduck@gmail.com>

* Update doc/tut2.md

Co-authored-by: Jacek Sieka <arnetheduck@gmail.com>
2022-12-15 06:45:36 +01:00
Tomohiro
92a0f191bf Use vccexe when generating static lib with vcc (#19843) 2022-09-28 15:07:41 +02:00
Andreas Rumpf
ca1f3f36b9 no ropes WIP (#20433)
* refactorings in preparation for ropes elimination of the C code generator; mostly the usual ': Rope' -> 'result: var Rope' rewrite
* rewrote ccgcalls.nim
* refactored ccgexprs.nim
* ccgliterals: refactoring
* refactoring: code dealing with name mangling
* refactoring: getRecordFieldsAux
* ropes are strings (insert obscene joke here)
* optimize JS code gen
* optimizations and code improvements
* more optimizations
* final cleanups
2022-09-27 10:57:47 +02:00
ringabout
47b59e4d33 fix #17351; switch to c++17 and remove hacks (#20407)
* fix #17351; switch to c++17

* remove workaround
2022-09-23 11:16:43 +02:00
kraptor
efcb89fa70 Correctly detect major version of GCC (#20059)
We were doing a very poor job detecting the major version of GCC by
parsing the output of --version.

This patches uses -dumpversion to make this parsing straightforward and
it also fixes a bunch of compiling issues on different platforms with
custom output for --version switches. For example, openSUSE first line
of the output includes the revision number and the parsing that was
being done did mix that number with the major version and breaks
building the nim compiler (as it doesn't find the 3 dots for an X.Y.Z semver
format, hence returning "false").

In this patch, we simply use -dumpversion (which has been at least from
1993, so we are safe :)
2022-07-18 21:24:39 +02:00
Daniel Clarke
489f6ddfef fix #20012 (#20013)
* replace gcc asm with __asm__ and add a test

* update test case to specify gcc or clang and not cpp

Co-authored-by: daniel <danielclarke@wearepopgun.com>
2022-07-13 20:55:33 +08:00
Jacek Sieka
ad430c0daa once C++, always C++ [backport] (#19938)
* once C++, always C++

When using `{.compile: "file.cc".}` in a nim module, even when compiling
with `nim c` the C++ compiler should be used - once any C++ file has
been compiled, the C++ linker also needs to be used.

* more strict C++ check

* simplify code
2022-06-30 10:20:19 +02:00
Don-Duong Quach
789b1bcbb6 Fixes #19883 so genscript works with vcc (#19893) 2022-06-15 08:20:34 +02:00
quantimnot
d30c6419a0 Refactor and doc package handling, module name mangling (#19821)
* Refactor and doc package handling, module name mangling

* Consolidate, de-duplicate and extend package handling
* Alter how duplicate module names of a package are handled
* Alter how module names are mangled
* Fix crash when another package is named 'stdlib' (test case added)
* Doc what defines a package in the manual

Modules with duplicate names within a package used to be given 'fake'
packages to resolve conflicts. That prevented the ability to discern if
a module belonged to the current project package or a foreign package.
They now have the proper package owner and the names are mangled in a
consistent manner to prevent codegen clashes.

All module names are now mangled the same. Stdlib was treated special
before, but now it is same as any other package. This fixes a crash
when a foreign package is named 'stdlib'.

Module mangling is altered for both file paths and symbols used by the
backends.

Removed an unused module name to package mapping that may have been
intended for IC. The mapping was removed because it wasn't being used
and was complicating the issue of package modules with duplicate names
not having the proper package owner assigned.

* Fix some tests

* Refactor `packagehandling`

* Remove `packagehandling.withPackageName` and its uses
* Move module path mangling from `packagehandling` to `modulepaths`
* Move `options.toRodFile` to `ic` to break import cycle

* Changed import style to match preferred style

Co-authored-by: quantimnot <quantimnot@users.noreply.github.com>
2022-05-30 18:52:19 +02:00
flywind
7f6e800caf move assertions out of system (#19599) 2022-03-23 20:34:53 +01:00
Ștefan Talpalaru
0c915b5e47 compile pragma: cache the result sooner (#19554)
extccomp.addExternalFileToCompile() relies on hashes to decide whether
an external C file needs recompilation or not.

Due to short-circuit evaluation of boolean expressions, the procedure
that generates a corresponding hash file is not called the first time an
external file is compiled, so an avoidable recompilation is triggered
the next build.

This patch fixes that by moving the proc call with a desired side
effect from its boolean expression, so it's executed unconditionally.
2022-02-24 08:31:40 +01:00
Timothee Cour
8540065754 --cc:env now works correctly to assign linker executable, allowing to cross-compile/run for windows on osx via wine (#18672)
* --cc:env now works correctly to assign linker executable, allowing using wine on osx

* fixup
2021-08-11 11:42:01 +02:00
flywind
9cb5ab0108 fix #18578 (#18580)
* fix #18578

* add tests

* tiny

* apply changes

* typo

* add removeStaticFile
2021-07-27 07:21:39 +02:00
Timothee Cour
9106ab7db1 make changeDetectedViaJsonBuildInstructions warning less verbose when json file invalid (eg due to spec change) (#18197) 2021-06-06 09:53:22 +02:00
Timothee Cour
654a20166e simplify extccomp.nim json logic via jsonutils; fix #18084 (#18100)
* simplify extccomp.nim json logic via jsonutils
* fix #18084
* simplify further
* workaround for bootstrap that can be removed after updating csources_v1 >= 1.2
2021-06-03 22:29:45 +02:00
Timothee Cour
927ae26fad externalToLink: use quoteShell to avoid issues with spaces in paths for {.link.} pragmas (#17875) 2021-04-29 09:01:00 +02:00
Timothee Cour
ffe4328b35 --usenimcache (implied by nim r main) now caches some compile options to avoid recompiling when project was previously compiled with such options. (#17829)
* `--usenimcache` (implied by `nim r main`) now caches some compile options
to avoid recompiling when project was previously compiled with such options.

* works
* add test
* changelog
* use std/with
2021-04-25 10:25:31 +02:00
Andreas Rumpf
a9b62de895 CIs: attempt to use csources_v1 (#16282)
* CIs: attempt to use csources_v1
* also updated the BSDs
* also updated azure pipelines
* std modules should not itself use the 'std/' import dir...
* compiler has to be careful with std/ for v1 booting
2021-04-21 07:41:33 +02:00
Timothee Cour
5c9c1988f6 -d:nimDebug: calls doAssert false instead of quit (#17739) 2021-04-17 11:49:54 +02:00
Timothee Cour
a75c4b70e8 hint:cc goes to stderr (like all other hints) instead of stdout (#17465)
Co-authored-by: ee7 <45465154+ee7@users.noreply.github.com>
2021-03-22 18:24:28 -07:00
flywind
874ccc8493 [minor] clean extccomp (#17069) 2021-02-17 15:48:17 +01:00
Timothee Cour
ba64d0c8ab fix #16947: --app:staticlib -o:lib now first removes lib (#16948) 2021-02-08 22:26:09 +01:00
Timothee Cour
6f6370367b fix #16949 --app:staticlib works on openbsd; --app:staticlib tested in CI (#16950) 2021-02-08 09:47:05 +01:00
Timothee Cour
854ff26ac5 fix #16206, nim r / nim -r recompiles if cwd changes (#16349) 2021-01-02 01:33:59 -08:00
Timothee Cour
8508c4e1c2 fix hintProcessing dots interference with static:echo and hintCC; add tests for nim secret, add tests for hintProcessing, misc other bug fixes (#16495)
* fix dots interfering with static:echo
* add tests
* fix hintProcessing dots for hintCC
* improve trunner tests
* fix bug: readLineFromStdin now writes prompt to stdout, consistent with linenoise and rdstdin
* disable a failing test for windows
2020-12-30 14:58:41 +01:00
Clyybber
92da06e64e Fix nimsuggest/#117 (#15602) 2020-11-15 15:08:27 +01:00
Timothee Cour
c1664f93b0 new: nim -e:cmd to run a command directly; also fixes #15731 (#15687)
* new: `nim -i cmd`
* rename -i to -e (for eval); consistent with majority of other programing languages
* `nim e -e:cmd` now works; bugfix: `echo cmd | nim e -` now works
* honor --betterRun
* address comments
* --eval alias for -e (replaces undocumented --eval which was a noop)
* --eval now defaults to e (nimscript) instead of r
* address comment: remove -e, only keep --eval
* address comment
* fixup
* Update compiler/nimconf.nim

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2020-11-09 16:07:22 +01:00
Andreas Rumpf
51e3e0c7c4 implements https://github.com/nim-lang/RFCs/issues/260 (#15505)
* implements https://github.com/nim-lang/RFCs/issues/260

* added a test case
2020-10-07 00:09:28 +02:00
Clyybber
13e659cfec Big compiler Cleanup (#14777) 2020-08-28 22:18:09 +02:00
Andreas Rumpf
49d4b50fe5 fixes #14194 (#15023) 2020-07-20 14:28:00 +02:00
Tomohiro
366b9a7e4a Fix #12745 (#14879) 2020-07-02 13:20:34 +02:00
Timothee Cour
01f6e505c8 bug fixes with sfMainModule, hints, mainPackageNotes, mainPackageId, hintSuccessX (#14555)
* SuccessX `out` now works with --compileOnly and jsonscript; fix bugs in jsonscript
* several bug fixes; eg: `nim doc lib/system/io` now is sane
* dummy edit to force docs CI
2020-06-04 10:40:17 +02:00