nim-lang / RFCs

A repository for your Nim proposals.
136 stars 26 forks source link

File specific localpassC for wrapped C/C++/ASM/(JS?) {.compile.} files #260

Closed mratsim closed 3 years ago

mratsim commented 3 years ago

We have a need to pass file-specific compilation flags to C or ASM files we are wrapping. For now we are using nim.cfg to specify the name of the files we want custom flags for.

See https://github.com/status-im/nim-beacon-chain/pull/1789

However this is a bandaid as it requires the final applications to copy those nim.cfg instead of setting it at the wrapper level.

Similar to localPassC (https://github.com/nim-lang/Nim/issues/12662) we would need file-level compilation flags for C/ASM files.

Proposals

Here are some ideas to implement this RFC.

  1. The compile pragma now accepts an optional passC string
  2. localPassC applies to local compile pragmas
  3. Introduce push/pop for passC/localpassC
arnetheduck commented 3 years ago

2 has the downside that the flags for the nim C code often need to be different that the .compile code - ie Nim generates pretty inefficient C code that might benefit from different compile options (like LTO) than the dependency being compiled - also, when compiling library code, it often needs "special" private defines and the like which should not be present for "users" of the code. If only 2 is implemented, one will have to create a special, separate compile-only module - feasible, but annoying.

Araq commented 3 years ago

We're going with (1).

Araq commented 3 years ago

Has been implemented, will ship in 1.4.