Skip to content

Commit

Permalink
[build] bump to mill 0.12.5 and refactor build scripts
Browse files Browse the repository at this point in the history
Signed-off-by: unlsycn <[email protected]>
  • Loading branch information
unlsycn committed Jan 14, 2025
1 parent 6a8222a commit 23e64f7
Show file tree
Hide file tree
Showing 12 changed files with 160 additions and 105 deletions.
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
12 changes: 6 additions & 6 deletions templates/chisel/flake.lock

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

13 changes: 7 additions & 6 deletions templates/chisel/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
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);
});
}
19 changes: 15 additions & 4 deletions templates/chisel/nix/gcd/gcd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{ lib
, stdenv
, fetchMillDeps
, publishMillModule
, makeWrapper
, jdk21
, git
Expand All @@ -20,6 +21,15 @@
}:

let
chisel =
publishMillModule {
name = "chisel";
version = "9999";
outputHash = "sha256-ZJGYxmTg4+8UU3V3MTxBSWow4XYKQ4KuCvD/PBxLSEc=";
publishPhase = "mill -i unipublish.publishLocal";
nativeBuildInputs = [ git ];
};

self = stdenv.mkDerivation rec {
name = "gcd";

Expand All @@ -29,8 +39,8 @@ let
toSource {
root = ./../..;
fileset = unions [
./../../build.sc
./../../common.sc
./../../build.mill
./../../common.mill
./../../gcd
./../../elaborator
];
Expand All @@ -42,9 +52,10 @@ let
src = with lib.fileset;
toSource {
root = ./../..;
fileset = unions [ ./../../build.sc ./../../common.sc ];
fileset = unions [ ./../../build.mill ./../../common.mill ];
};
millDepsHash = "sha256-5VTgJ1JaIxP3wk/WsFj+W1VGFE2xoPKu3XbmTVOvMdk=";
millDepModules = [ chisel ];
millDepsHash = "sha256-cPGkRjKc42dcSOXHAW9JAl/AKgwPdl+T8bVPsWCXxpM=";
nativeBuildInputs = [ projectDependencies.setupHook ];
};

Expand Down
2 changes: 2 additions & 0 deletions templates/chisel/nix/overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ final: prev: {

fetchMillDeps = final.callPackage ./pkgs/mill-builder.nix { };

publishMillModule = final.callPackage ./pkgs/dependencies { };

circt-full = final.callPackage ./pkgs/circt-full.nix { };

# faster strip-undetereminism
Expand Down
10 changes: 5 additions & 5 deletions templates/chisel/nix/pkgs/dependencies/_sources/generated.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"chisel": {
"cargoLocks": null,
"date": "2024-10-28",
"date": "2025-01-09",
"extract": null,
"name": "chisel",
"passthru": null,
Expand All @@ -11,12 +11,12 @@
"fetchSubmodules": false,
"leaveDotGit": false,
"name": null,
"owner": "chipsalliance",
"owner": "unlsycn",
"repo": "chisel",
"rev": "66bab812796eb5a5c0bbe3308ee01fc6752557eb",
"sha256": "sha256-gaaNEGqxm213vQ3er6vn7kC8na0D745IdDnJWwQPgms=",
"rev": "ea01f89d39c138bc4c260baf5e8e088e120f4265",
"sha256": "sha256-KNcAgOA/YBt+1QOVXGpK/33BZ8PpDcHDdAnIBDLfSqI=",
"type": "github"
},
"version": "66bab812796eb5a5c0bbe3308ee01fc6752557eb"
"version": "ea01f89d39c138bc4c260baf5e8e088e120f4265"
}
}
10 changes: 5 additions & 5 deletions templates/chisel/nix/pkgs/dependencies/_sources/generated.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
{
chisel = {
pname = "chisel";
version = "66bab812796eb5a5c0bbe3308ee01fc6752557eb";
version = "ea01f89d39c138bc4c260baf5e8e088e120f4265";
src = fetchFromGitHub {
owner = "chipsalliance";
owner = "unlsycn";
repo = "chisel";
rev = "66bab812796eb5a5c0bbe3308ee01fc6752557eb";
rev = "ea01f89d39c138bc4c260baf5e8e088e120f4265";
fetchSubmodules = false;
sha256 = "sha256-gaaNEGqxm213vQ3er6vn7kC8na0D745IdDnJWwQPgms=";
sha256 = "sha256-KNcAgOA/YBt+1QOVXGpK/33BZ8PpDcHDdAnIBDLfSqI=";
};
date = "2024-10-28";
date = "2025-01-09";
};
}
47 changes: 47 additions & 0 deletions templates/chisel/nix/pkgs/dependencies/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{ pkgs
, stdenv
, mill
, ...
}:
{ name
, version
, outputHash
, publishPhase
, ...
}@args:
let
dependencies = pkgs.callPackage ./_sources/generated.nix { };
in
stdenv.mkDerivation {
pname = name;
src = dependencies.${name}.src;

inherit version outputHash;

outputHashAlgo = "sha256";
outputHashMode = "recursive";

nativeBuildInputs = [ mill ] ++ (args.nativeBuildInputs or [ ]);

impureEnvVars = [ "JAVA_OPTS" ];

buildPhase = ''
runHook preBuild
echo "-Duser.home=$TMPDIR -Divy.home=$TMPDIR/ivy $JAVA_OPTS" | tr ' ' '\n' > mill-java-opts
export MILL_JVM_OPTS_PATH=$PWD/mill-java-opts
# Use "https://repo1.maven.org/maven2/" only to keep dependencies integrity
export COURSIER_REPOSITORIES="ivy2Local|central"
${publishPhase}
runHook postBuild
'';

installPhase = ''
runHook preInstall
mkdir -p $out/.ivy2
mv $TMPDIR/ivy/local $out/.ivy2/local
runHook postInstall
'';
}
6 changes: 3 additions & 3 deletions templates/chisel/nix/pkgs/dependencies/nvfetcher.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[chisel]
src.git = "https://github.com/chipsalliance/chisel"
src.branch = "main"
fetch.github = "chipsalliance/chisel"
src.git = "https://github.com/unlsycn/chisel"
src.branch = "mill-bump"
fetch.github = "unlsycn/chisel"
Loading

0 comments on commit 23e64f7

Please sign in to comment.