|
| 1 | +How to use a local SpinalHDL clone as project dependency |
| 2 | +======================================================== |
| 3 | + |
| 4 | +The default way to use SpinalHDL is by using the released version of it as is |
| 5 | +automatically downloaded by sbt or mill. Living on the cutting edge, you might |
| 6 | +want to use the upstream and non released ``dev`` branch from git directly. Be |
| 7 | +it just because you want to use a new shiny feature or because you want to test |
| 8 | +your own extension to Spinal (please consider upstreaming it by opening a PR) |
| 9 | +within a project. |
| 10 | + |
| 11 | +As an example of where this is used you can also refer to `VexiiRiscv`_. |
| 12 | + |
| 13 | + |
| 14 | +Create local git clone of SpinalHDL |
| 15 | +----------------------------------- |
| 16 | + |
| 17 | +.. code-block:: sh |
| 18 | +
|
| 19 | + cd /somewhere |
| 20 | + git clone --depth 1 -b dev https://github.com/SpinalHDL/SpinalHDL.git |
| 21 | +
|
| 22 | +In the command above you can replace ``dev`` by the name of the branch you want |
| 23 | +to checkout. ``--depth 1`` prevents from downloading the repository history. |
| 24 | + |
| 25 | + |
| 26 | +Configure buildsystem |
| 27 | +--------------------- |
| 28 | + |
| 29 | +Depending on which tool you use, instruct either sbt or mill to load the local |
| 30 | +git folder as dependency: |
| 31 | + |
| 32 | + |
| 33 | +Configure sbt (update ``build.sbt``) |
| 34 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 35 | + |
| 36 | +.. code-block:: scala |
| 37 | +
|
| 38 | + ThisBuild / version := "1.0" // change as needed |
| 39 | + ThisBuild / scalaVersion := "2.12.18" // change as needed |
| 40 | + ThisBuild / organization := "org.example" // change as needed |
| 41 | +
|
| 42 | + val spinalRoot = file("/somewhere/SpinalHDL") |
| 43 | + lazy val spinalIdslPlugin = ProjectRef(spinalRoot, "idslplugin") |
| 44 | + lazy val spinalSim = ProjectRef(spinalRoot, "sim") |
| 45 | + lazy val spinalCore = ProjectRef(spinalRoot, "core") |
| 46 | + lazy val spinalLib = ProjectRef(spinalRoot, "lib") |
| 47 | +
|
| 48 | + lazy val projectname = (project in file(".")) |
| 49 | + .settings( |
| 50 | + Compile / scalaSource := baseDirectory.value / "hw" / "spinal", |
| 51 | + ).dependsOn(spinalIdslPlugin, spinalSim, spinalCore, spinalLib) |
| 52 | +
|
| 53 | + scalacOptions += (spinalIdslPlugin / Compile / packageBin / artifactPath).map { file => |
| 54 | + s"-Xplugin:${file.getAbsolutePath}" |
| 55 | + }.value |
| 56 | +
|
| 57 | + fork := true |
| 58 | +
|
| 59 | +
|
| 60 | +Configure mill (update ``build.sc``) |
| 61 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 62 | + |
| 63 | +.. code-block:: scala |
| 64 | +
|
| 65 | + import mill._, scalalib._ |
| 66 | +
|
| 67 | + import $file.^.SpinalHDL.build |
| 68 | + import ^.SpinalHDL.build.{core => spinalCore} |
| 69 | + import ^.SpinalHDL.build.{lib => spinalLib} |
| 70 | + import ^.SpinalHDL.build.{idslplugin => spinalIdslplugin} |
| 71 | +
|
| 72 | + val spinalVers = "1.10.2a" |
| 73 | + val scalaVers = "2.12.18" |
| 74 | +
|
| 75 | + object projectname extends RootModule with SbtModule { |
| 76 | + def scalaVersion = scalaVers |
| 77 | + def sources = T.sources( |
| 78 | + this.millSourcePath / "hw" / "spinal" |
| 79 | + ) |
| 80 | +
|
| 81 | + def idslplugin = spinalIdslplugin(scalaVers) |
| 82 | + def moduleDeps = Seq( |
| 83 | + spinalCore(scalaVers), |
| 84 | + spinalLib(scalaVers), |
| 85 | + idslplugin |
| 86 | + ) |
| 87 | + def scalacOptions = super.scalacOptions() ++ idslplugin.pluginOptions() |
| 88 | + } |
| 89 | +
|
| 90 | +
|
| 91 | +Note the line ``import $file.^.SpinalHDL.build``. It is using ammonite REPL |
| 92 | +magic ``$file`` to look up the ``build.sc`` of SpinalHDL. (The ``^`` moves up |
| 93 | +one directory from the current.) This is assuming the following directory |
| 94 | +structure: |
| 95 | + |
| 96 | +.. code-block:: scala |
| 97 | +
|
| 98 | + /somewhere |
| 99 | + |-SpinalHDL # <-- cloned spinal git |
| 100 | + | |-build.sc |
| 101 | + |-projectname |
| 102 | + | |-build.sc # <-- your project, mill is ran from here |
| 103 | +
|
| 104 | +
|
| 105 | +Done |
| 106 | +---- |
| 107 | + |
| 108 | +Note the addition to ``scalacOptions``. Without it, compiling any Spinal project |
| 109 | +might produce countless ``SCOPE VIOLATION`` or ``HIERARCHY VIOLATION`` errors |
| 110 | +because the ``idslplugin`` of spinal is not actually invoked. |
| 111 | + |
| 112 | +After the changes, the next compilation of your project will take a considerable |
| 113 | +amount of time (~2 minutes). This is only for the first compile. After this, |
| 114 | +your project should compile as usual. |
| 115 | + |
| 116 | + |
| 117 | +.. _VexiiRiscv: https://github.com/SpinalHDL/VexiiRiscv/blob/dev/build.sbt |
0 commit comments