From looking at other nim repos, it looks like the accepted pattern if you are making a library is to have a src directory under your pojects root directory with the library code. Then an example directory under the root for example code. How do you set this up so that you can conveniently compile and run the example programs?
Currently my nimble file is:
# Package
version = "0.1.0"
author = "Jack Mott"
description = "type safe opengl wrapper"
license = "MIT"
bin = @["../examples/example02"]
srcDir = "src"
# Dependencies
requires "nim >= 0.17.0"
requires "sdl2"
requires "opengl"
and my examples dir has a nim.cfg with --path:"../src"
This works until it tries to produce the executable at root/../examples/example02.exe and that dir doesn't exist, it should be root/examples/example02.exe
Any tips?
I think I found the answers I need here: https://github.com/nim-lang/nimble#project-structure
In case anyone else finds this with a search, this worked:
# Package
version = "0.1.0"
author = "Jack Mott"
description = "type safe opengl wrapper"
license = "MIT"
srcDir = "src"
# Dependencies
requires "nim >= 0.17.0"
requires "sdl2"
requires "opengl"
requires "stb_image"
task hello_triangle, "Runs hello triangle":
exec "nim c -r examples/hello_triangle"
task shaders, "Runs shaders":
exec "nim c -r examples/shaders"
You can also use nimscript to create the dir ( eg mkdir "tests"), or do some nice things like build all tests in a dir, eg
import ospaths
task tests, "Runs tests":
withdir "tests":
for file in listfiles("."):
if splitfile(file).ext == ".nim":
exec "nim c -r --verbosity:0 --hints:off " & file