LoginSignup
3
1

More than 5 years have passed since last update.

自作nimbleモジュールのバージョンをいい感じにする

Posted at

概要

*.nimbleファイルにバージョンを直書きするのはなんだかなー、と思っていたらnimble自体の.nimbleファイル(ややこしい)がいい感じになっていたのでコピペした。

説明

.nimbleファイル内ではnimの文法が使用可能なのでsrcディレクトリ内のファイルで定義してやればよい。

exampleというパッケージ名の場合、

src/examplepkg/common.nim
const exampleVersion* = "0.1.0"
example.nimble
import ospaths

# フルパス取得用テンプレート
template thisModuleFile: string = instantiationInfo(fullPaths = true).filename

# 存在確認
when fileExists(thisModuleFile.parentDir / "src/examplepkg/common.nim"):
  # コンパイル (nimble install)時
  import src/examplepkg/common
else:
  # nimble installするとsrcディレクトリが展開されるので
  import examplepkg/common

# Package

version = exampleVersion
~
~

注意点

nimble initの際、Package typeにbinaryを選択(binがあってinstallExtが無い状態?)するとsrcディレクトリが消えるのでこの方法は使用不可。

まとめ

いつの間にかnimble initでパッケージタイプごとのプロジェクトテンプレートが生成されるようになったりしてた。

宣伝

結構前から作ってるnimのREPLっぽいもの。
https://github.com/mkanenobu/nimre

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1