Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[build] bump to mill 0.12.5 and refactor build scripts #61

Merged
merged 11 commits into from
Feb 9, 2025
2 changes: 2 additions & 0 deletions .github/workflows/checkfmt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ jobs:
- name: "Check Scala format"
if: "!cancelled()"
run: |
echo "$JAVA_OPTS" | tr ' ' '\n' > mill-java-opts
export MILL_JVM_OPTS_PATH=$PWD/mill-java-opts
nix develop -c bash -c 'mill -i gcd.checkFormat && mill -i elaborator.checkFormat'
- name: "Check Rust format"
if: "!cancelled()"
Expand Down
43 changes: 13 additions & 30 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ It will provide you the below code structure:
* gcdemu/: source code for the DPI library
* configs/: default configurations for GCD and the testbench, which can be generated by elaborator
* nix/: nix build script for the whole lowering process
* build.sc & common.sc: Scala build script
* build.mill & common.mill: Scala build script
* flake.nix: the root for nix to search scripts

## Usage
Expand Down Expand Up @@ -145,7 +145,7 @@ To bump mill dependencies, run:
nix build '.#gcd.gcd-compiled.millDeps' --rebuild
```

and Then update `millDepsHash` in `nix/gcd/gcd.nix`
and Then update `millDepsHash` in `nix/pkgs/dependencies/default.nix` and `nix/gcd/gcd.nix`

### Use the fetchMillDeps function

Expand All @@ -154,7 +154,7 @@ Fetch project dependencies for later offline usage.
The `fetchMillDeps` function accept three args: `name`, `src`, `millDepsHash`:

* name: name of the mill dependencies derivation, suggest using `<module>-mill-deps` as suffix.
* src: path to a directory that contains at least `build.sc` file for mill to obtain dependencies.
* src: path to a directory that contains at least `build.mill` file for mill to obtain dependencies.
* millDepsHash: same functionality as the `sha256`, `hash` attr in stdenv.mkDerivation. To obtain new hash for new dependencies, replace the old hash with empty string, and let nix figure the new hash.

This derivation will read `$JAVA_OPTS` environment varialble, to set http proxy, you can export:
Expand All @@ -171,15 +171,17 @@ Example:
```nix
stdenv.mkDerivation rec {
# ...
millDeps = fetchMillDeps {
inherit name;
src = with lib.fileset; toSource {
root = ./.;
fileset = unions [
./build.sc
];
passthru = {
millDeps = fetchMillDeps {
inherit name;
src = with lib.fileset;
toSource {
root = ./../..;
fileset = unions [ ./../../build.mill ./../../common.mill ];
};
buildInputs = with mill-dependencies; [ chisel.setupHook ];
millDepsHash = "sha256-NybS2AXRQtXkgHd5nH4Ltq3sxZr5aZ4VepiT79o1AWo=";
};
millDepsHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
};
# ...
nativeBuildInputs = [
Expand All @@ -189,25 +191,6 @@ stdenv.mkDerivation rec {
}
```

### Use the `nvfetcherSource` attribute

`projectDependencies` attribute is an nix setup hook that will obtain nvfetcher generated sources
and place them under `dependencies` directory in build root.

Read [nvfetcher](https://github.com/berberman/nvfetcher) document for nvfetcher usage.
By default the `nvfetcherSource` attribute will read `nix/pkgs/dependencies/_sources/generated.nix`,
so developer should place nvfetcher config and run `nix run .#nvfetcher` under `nix/pkgs/dependencies`.

Usage:

```nix
stdenv.mkDerivation {
nativeBuildInputs = [
projectDependencies.setupHook
]
}
```

## License

The build system is released under the Apache-2.0 license, including all Nix and mill build system, All rights reserved by Jiuyang Liu <[email protected]>
Expand Down
48 changes: 48 additions & 0 deletions templates/chisel/build.mill
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2024 Jiuyang Liu <[email protected]>
package build

import mill._
import mill.scalalib._
import mill.define.{Command, TaskModule}
import mill.scalalib.publish._
import mill.scalalib.scalafmt._
import mill.scalalib.TestModule.Utest
import mill.util.Jvm
import coursier.maven.MavenRepository

object deps {
val scalaVer = "2.13.15"
val mainargs = ivy"com.lihaoyi::mainargs:0.5.0"
val oslib = ivy"com.lihaoyi::os-lib:0.9.1"
val upickle = ivy"com.lihaoyi::upickle:3.3.1"
val chisel = ivy"org.chipsalliance::chisel::0.0.0+0-no-vcs-SNAPSHOT"
val chiselPlugin = ivy"org.chipsalliance:chisel-plugin_${scalaVer}:0.0.0+0-no-vcs-SNAPSHOT"
}

object gcd extends GCD
trait GCD extends common.HasChisel with ScalafmtModule {
def scalaVersion = Task(deps.scalaVer)

def chiselModule = None
def chiselPluginJar = Task(None)
def chiselPluginIvy = Some(deps.chiselPlugin)
def chiselIvy = Some(deps.chisel)
}

object elaborator extends Elaborator
trait Elaborator extends common.ElaboratorModule with ScalafmtModule {
def scalaVersion = Task(deps.scalaVer)

def circtInstallPath =
Task.Input(PathRef(os.Path(T.ctx().env("CIRCT_INSTALL_PATH"))))

def generators = Seq(gcd)

def mainargsIvy = deps.mainargs

def chiselModule = None
def chiselPluginJar = Task(None)
def chiselPluginIvy = Some(deps.chiselPlugin)
def chiselIvy = Some(deps.chisel)
}
66 changes: 0 additions & 66 deletions templates/chisel/build.sc

This file was deleted.

4 changes: 2 additions & 2 deletions templates/chisel/common.sc → templates/chisel/common.mill
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2024 Jiuyang Liu <[email protected]>
package build

import mill._
import mill.scalalib._
Expand Down Expand Up @@ -39,9 +40,8 @@ trait HasChisel extends ScalaModule {

trait ElaboratorModule extends ScalaModule with HasChisel {
def generators: Seq[ScalaModule]
def panamaconverterModule: ScalaModule
def circtInstallPath: T[PathRef]
override def moduleDeps = super.moduleDeps ++ Seq(panamaconverterModule) ++ generators
override def moduleDeps = super.moduleDeps ++ generators
def mainargsIvy: Dep
override def ivyDeps = T(super.ivyDeps() ++ Seq(mainargsIvy))
override def javacOptions = T(super.javacOptions() ++ Seq("--enable-preview", "--release", "21"))
Expand Down
28 changes: 22 additions & 6 deletions templates/chisel/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 10 additions & 8 deletions templates/chisel/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
chisel-nix.url = "github:chipsalliance/chisel-nix";
};

outputs = inputs@{ self, nixpkgs, flake-utils }:
outputs = inputs@{ self, nixpkgs, flake-utils, chisel-nix }:
let overlay = import ./nix/overlay.nix;
in {
# System-independent attr
Expand All @@ -17,18 +18,19 @@
} // flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
overlays = [ overlay ];
overlays = [ overlay chisel-nix.overlays.mill-flows ];
inherit system;
};
in
with pkgs;
{
formatter = pkgs.nixpkgs-fmt;
formatter = nixpkgs-fmt;
legacyPackages = pkgs;
devShells.default = pkgs.mkShell ({
inputsFrom = [ pkgs.gcd.gcd-compiled pkgs.gcd.tb-dpi-lib ];
nativeBuildInputs = [ pkgs.cargo pkgs.rustfmt pkgs.rust-analyzer ];
devShells.default = mkShell ({
inputsFrom = [ gcd.gcd-compiled gcd.tb-dpi-lib ];
packages = [ cargo rustfmt rust-analyzer nixd nvfetcher ];
RUST_SRC_PATH =
"${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
} // pkgs.gcd.tb-dpi-lib.env // pkgs.gcd.gcd-compiled.env);
"${rust.packages.stable.rustPlatform.rustLibSrc}";
} // gcd.tb-dpi-lib.env // gcd.gcd-compiled.env);
});
}
29 changes: 9 additions & 20 deletions templates/chisel/nix/gcd/gcd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
, git

# chisel deps
, mill-dependencies
, mill
, espresso
, circt-full
, jextract-21
, add-determinism
, projectDependencies

, target
}:
Expand All @@ -29,8 +29,8 @@ let
toSource {
root = ./../..;
fileset = unions [
./../../build.sc
./../../common.sc
./../../build.mill
./../../common.mill
./../../gcd
./../../elaborator
];
Expand All @@ -42,39 +42,28 @@ let
src = with lib.fileset;
toSource {
root = ./../..;
fileset = unions [ ./../../build.sc ./../../common.sc ];
fileset = unions [ ./../../build.mill ./../../common.mill ];
};
millDepsHash = "sha256-5VTgJ1JaIxP3wk/WsFj+W1VGFE2xoPKu3XbmTVOvMdk=";
nativeBuildInputs = [ projectDependencies.setupHook ];
buildInputs = with mill-dependencies; [ chisel.setupHook ];
millDepsHash = "sha256-NybS2AXRQtXkgHd5nH4Ltq3sxZr5aZ4VepiT79o1AWo=";
};

editable = self.overrideAttrs (_: {
shellHook = ''
setupSubmodulesEditable
mill mill.bsp.BSP/install 0
'';
});

inherit target;
inherit env;
};

shellHook = ''
setupSubmodules
'';
nativeBuildInputs = with mill-dependencies; [
makeWrapper

nativeBuildInputs = [
mill
circt-full
jextract-21
add-determinism
espresso
git

makeWrapper
passthru.millDeps.setupHook

projectDependencies.setupHook
chisel.setupHook
];

env = {
Expand Down
2 changes: 1 addition & 1 deletion templates/chisel/nix/gcd/rtl.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
, enable-layers ? [ ]
}:
let
processLayer = lib.map (str: "./" + lib.replaceStrings [ "." ] [ "/" ] str);
processLayer = lib.map (str: "./" + lib.replaceStrings [ "." ] [ "/" ] (lib.toLower str));
enableLayersDirs = processLayer enable-layers;
in
stdenvNoCC.mkDerivation {
Expand Down
Loading