nimble icon indicating copy to clipboard operation
nimble copied to clipboard

`when not defined(release)` is always true for dependencies

Open oakes opened this issue 5 years ago • 6 comments

In my nimble file, the following seems to require the dependency even when I run nimble build -d:release:

when not defined(release):
  requires "my_library >= 1.0.0"

Is there some other way to specify dev dependencies that are not included in a release build?

oakes avatar Apr 10 '20 01:04 oakes

This should be fixed - can you please try with nim devel, or nimble install nimble@#head and see if it works for you?

genotrance avatar Sep 02 '20 14:09 genotrance

I tested it on the latest devel on windows 10 and have not been able to get it to work so far. I'm testing it on this game project.

First i put the dev dependency inside a when:

diff --git a/parakeet.nimble b/parakeet.nimble
index 6142e4e..26e2800 100644
--- a/parakeet.nimble
+++ b/parakeet.nimble
@@ -19,4 +19,5 @@ requires "stb_image >= 2.5"

 # Dev Dependencies

-requires "paravim >= 0.18.0"
+when not defined(release):
+  requires "paravim >= 0.18.0"

Then i ran the following:

nimble build -d:release -d:paravim

That should cause a compile error, because -d:paravim is what brings in the dev dependency. But so far the command still works, and i still see paravim in the nimble output.

Nim Compiler Version 1.3.5 [Windows: amd64]
Compiled at 2020-09-03
Copyright (c) 2006-2020 by Andreas Rumpf

git hash: 48f29972210612b41cb6d98122672b1713edc907
active boot switches: -d:release

oakes avatar Sep 03 '20 11:09 oakes

This is not supported today - flags are not forwarded to nim when parsing the nimble file for requires statements and other details.

@dom96 @Araq do we want to enable this? It can potentially break printPkgInfo parsing of the nimble file that leverages nim e.

https://github.com/nim-lang/nimble/blob/master/src/nimblepkg/nimscriptwrapper.nim#L48

genotrance avatar Sep 04 '20 20:09 genotrance

@genotrance I think forwarding of --define is rather unproblematic and the obvious behaviour people expect. Probably that's true for every other non-Nimble specific flag.

Araq avatar Sep 07 '20 10:09 Araq

I spent some time looking at this. There are some code structure challenges, but even keeping those aside, requires statements are handled in printPkgInfo which is run only once and after that it is cached. To implement this feature, printPkgInfo caching will need to depend on the command-line compile flags which might not even be supported for commands like nimble dump. It seems like it might be prudent to live with this limitation that only really affects requires statements.

genotrance avatar Sep 08 '20 02:09 genotrance

Unfortunately for Nim users, requires statements are really the only reason to have a .nimble file.

disruptek avatar Jan 14 '21 21:01 disruptek