Skip to content

Instantly share code, notes, and snippets.

@genotrance
Last active January 28, 2020 23:46
Show Gist options
  • Save genotrance/35504ed532f9cb836f11fd02b5bf1145 to your computer and use it in GitHub Desktop.
Save genotrance/35504ed532f9cb836f11fd02b5bf1145 to your computer and use it in GitHub Desktop.
Nimble RFCs for Araq

nim.cfg based interop

Nimble requirements

  • Add a new command called nimble usecfg
    • Creates/updates nimbledeps.cfg
    • Adds --path entries for all dependencies
    • Includes --clearNimblePath as well to remove any scanned packages already added
    • Uses @include in nim.cfg to load nimbledeps.cfg if it exists
  • Nimble should detect if project is in usecfg mode
    • Check if nimbledeps.cfg exists and is being @include'ed
  • Nimble functions like today if not in usecfg mode
    • User needs to opt in and use nimble usecfg once for project to get into this mode
  • When in usecfg mode
    • Commands like nimble c, nimble build, nimble docs should execute usecfg before calling Nim
    • Above commands should no longer pass --path via CLI arguments to Nim
    • When saving to nimbledeps.cfg, Nimble should optimize if file really needs to be updated or if it is up to date
  • Backwards compatibility
    • Need to handle packages with existing nim.cfg without breakage - Need to handle cases where nim.cfg already has some --path or --nimblePath instances added by user
    • Need to ensure compatibility with existing config.nims
  • This change should work with standard ~/.nimble as well as a custom --nimbleDir - Need to evaluate impacts on other Nim tools that could potentially update nim.cfg or hard-code paths

Nim requirements

  • Nim should support $nimbleDir substitution in --path calls to enable relative paths - DONE
    • $nimblePath and $nimbleDir both are supported
    • Handled differently than other $ substitutions since it is one to many
    • Every $nimbleDir added to Nim will be added to searchPaths
      • If $nimbleDir = ["$home/.nimble/pkgs", "$projectpath/nimbledeps/pkgs"]
      • --path:"$nimbleDir/pkg-0.1.0" will searchPaths.add(["$projectpath/nimbledeps/pkgs/pkg-0.1.0", "$home/.nimble/pkgs/pkg-0.1.0"])
    • nim-lang/Nim#12750
  • Nim should support @include directive to nim.cfg that allows including a separate file
    • Syntax @include "path/to/file" or @include varName
    • Path should be processed with pathSubs() to allow $projectpath style substitutions
    • If path specified does not exist, Nim will fail
    • Behavior if older Nim loads @include - what happens
  • Nim should support @if fileExists("path/to/file) or @if fileExists(varName)
    • Allow optional @include of separate files - @if fileExists(fName): @include fName @end
    • Behavior if older Nim loads @if fileExists - what happens

nimble develop --recurse

Recursive develop - the ability to actively develop a project and all its dependencies locally.

Nimble requirements

  • Need a new nimble develop --recurse flag that sets all dependencies in a local nimble develop mode
    • Main project is checked out with nimble develop
    • Each dependency is also checked out with nimble develop mode
    • Each dependency is stored in a project local nimbledeps directory and not the global $nimbleDir
  • --recurse should work with usecfg as well as standard Nimble behavior
    • usecfg works well for --recurse but forcing it would result in nim.cfg changes that user may not want to check in
    • Standard Nimble behavior can use --nimbleDir but that too will need nim.cfg changes
    • Unclear at this point how standard Nimble behavior can coexist with --recurse - open to ideas
@genotrance
Copy link
Author

Updated editcfg to modecfg after discussion with @Araq since it suggests a change in Nimble behavior beyond a single command.

@genotrance
Copy link
Author

Added nimble develop --recurse RFC as well into this same gist.

@genotrance
Copy link
Author

One concern with modecfg - we will be passing --noNimblePath so that Nim will no longer search $nimbleDir for dependencies itself but simply use the --path packages specified.

However, modecfg does require relative paths and we have proposed $nimbleDir substitution in --path entries that Nim will handle. So this means that Nim won't search $nimbleDir itself but will still need to be aware of $nimbleDir when --noNimblePath is specified. i.e. on Posix, default to ~/.nimble or %APPDATA%\.nimble on Windows.

I think this should be okay but just wanted to highlight it.

@Araq
Copy link

Araq commented Nov 22, 2019

I think this should be okay

I completely agree.

@genotrance
Copy link
Author

Added $nimbleDir substitution implementation details in Nim and PR link

@dom96
Copy link

dom96 commented Nov 27, 2019

This is looking good, although I might raise things in your PRs, so don't take this as a promise that I won't find something that I want changed.

One small thing I will do now is bikeshed :) Can we call this nimble usecfg instead?

@genotrance
Copy link
Author

@dom96 - absolutely - expected and welcome.

I'll go with usecfg.

@genotrance
Copy link
Author

Updates:

  • Introduce @include and @if fileExists Nim features
  • Update usecfg to use @include instead
  • Replace modecfg with usecfg

@dom96
Copy link

dom96 commented Jan 28, 2020

Is this still being worked on?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment