The build

histos.scala describes what you want built. Histos turns that description into work it can compile, test, and publish. Two words are enough to read the file.

A module is a named piece of the project, the thing you would have called a subproject. You give it one or more platforms and one or more Scala versions.

A cell is one combination: one module, one Scala version, and one platform. Compile, test, and publish run on a cell. If a module is built for the JVM and for Scala.js, those are two cells, and a change in one does not by itself rebuild the other.

Platforms

There are three platforms. Jvm is a JVM program or library. Js is Scala.js. Native is Scala Native. On the command line the tokens are jvm, js, and native. histos run <module> --platform js selects that module's Scala.js cell, if it supports Scala.js. Positional platform tokens are not run selectors.

--scala 2.13 and --scala 3 select a series. --scala 2.13.18 selects that full version. Omission keeps every declared version of the modules you asked for. A named module refuses a token that matches nothing and a series that matches two of its versions. histos run starts one process, so it needs one Scala version and one platform.

histos.Platform.token
def token: String = this match
    case Jvm    => "jvm"
    case Js     => "js"
    case Native => "native"
histos.ScalaSelection.require
  /** A named module. Each token matches exactly one declared version. */
  def require(module: ProjectName, declared: List[ScalaVersion]): Either[SelectionError, List[ScalaVersion]] =
    this match
      case All               => Right(declared.distinct)
      case Only(first, rest) =>
        ScalaSelection
          .distinctTokens(first :: rest)
          .foldLeft[Either[SelectionError, List[ScalaVersion]]](Right(Nil)): (acc, token) =>
            acc.flatMap: found =>
              declared.filter(ScalaSelection.matches(token, _)).distinct match
                case Nil       => Left(SelectionError.UnsupportedScala(module, token))
                case List(one) => Right(if found.contains(one) then found else found :+ one)
                case many      => Left(SelectionError.AmbiguousScala(module, token, many))

Versions and dependencies are checked when the build file compiles

You write a Scala version as scala"x.y.z" and a dependency as dep"org::name:revision". Those are macros. A version that is not a full Scala version, or a dependency that is not a real coordinate, fails compilation of histos.scala. Histos never gets as far as resolving it. Bind the ship once. Ship("name").parent(Jvm)(scala"3.8.1") is the member named like the ship. ship.next(major, minor, patch)(the modules) is the catalog row. The number on next is the next release. You do not write SNAPSHOT in the catalog.

histos.Dep.from
def from(raw: String): Either[DepError, Dep] =
    if raw.isEmpty then Left(DepError.Empty)
    else if raw.exists(_.isWhitespace) then Left(DepError.BadShape(raw))
    else parse(raw)

Sources live in more than one directory

A module compiles the sources under its own directory. That is <name>/src, or the directory you named with in.

When the same tree belongs in more than one module, add it with sources. Each extra directory uses the layout you already know: scala, java, and a filter such as jvm, js, native, or scala-2.13. A file under jvm is compiled for the JVM and left out of Scala.js. The module directory stays the first root. Naming a directory twice does not compile it twice.

val shared = path"shared/src"
val core   = module("core", Jvm, Js)(scala"3.8.1").sources(shared)
histos.Module.sources
sources: List[ProjectPath] = Nil

Main, Test, and exact roots

A cell has two compiler stages: SourceSet.Main and SourceSet.Test. Test includes its own Main classes. Conventional <module>/src and <module>/test trees remain available. Use roots for directories that do not follow that layout: each ScopedRoot names an exact directory, its scope, platforms, and whether it contains sources or resources. Histos does not expand a scoped root into layout subdirectories. ScopedRoot.jvmNative selects the combined JVM/Native tree, not Scala.js.

dependsOn(core) supplies Main products. testDependsOn(core) additionally supplies core's Test classes and resources to the depender's Test stage. Use it for shared fixtures, not to request core's suites. Only selected modules' suites run. Test-only project edges and testDependencies do not enter Main classpaths or published POMs. Platform-specific fixture edges use testDependsOn(Jvm)(core).

histos.CompilationStage
final case class CompilationStage(cell: Cell, scope: SourceSet)
histos.ScopedRoot
/** An exact repository-relative directory, without implicit layout expansion. Generated File consumption uses
  * [[histos.plugin.EmittedContent]], never a widened parent [[ScopedRoot]].
  */
final case class ScopedRoot(
    path: RepoPath,
    scope: SourceSet,
    platforms: PlatformSelection,
    kind: RootKind,
)
{
  import histos.*
  import histos.Platform.*
  import histos.plugin.{RepoPath, SourceSet}

  val fixtures = module("fixtures", Jvm)(scala"3.8.1")
  val core     = module("core", Jvm, Js)(scala"3.8.1")
    .roots(
      ScopedRoot(RepoPath("shared/main"), SourceSet.Main, PlatformSelection.only(Jvm), RootKind.Sources),
      ScopedRoot(RepoPath("shared/test-data"), SourceSet.Test, PlatformSelection.All, RootKind.Resources),
    )
    .testDependsOn(Jvm)(fixtures)
  val graph = ZIO.fromEither(Projects(fixtures, core))
  graph
}
ProjectGraph(List(Module(fixtures,Platforms(Jvm,List()),ScalaVersions(3.8.1,List()),List(),List(),SourcePos(_checkout_/docs/src/main/scalajvm/histos/docs/BuildModel.scala,98,24),Unused,None,List(),None,None,None,None,Node,NoModule,None,List(),List(),None,Library,None,Off,Set(),List(),8m,None,List(),Set(),List(),Suite,List(),None,None,JvmOptions(List(),List()),None), Module(core,Platforms(Jvm,List(Js)),ScalaVersions(3.8.1,List()),List(),List(ProjectDep(fixtures,Some(List(Jvm)),Test)),SourcePos(_checkout_/docs/src/main/scalajvm/histos/docs/BuildModel.scala,99,24),Unused,None,List(),None,None,None,None,Node,NoModule,None,List(),List(),None,Library,None,Off,Set(),List(),8m,None,List(),Set(),List(),Suite,List(ScopedRoot(shared/main,Main,Only(Platforms(Jvm,List())),Sources), ScopedRoot(shared/test-data,Test,All,Resources)),None,None,JvmOptions(List(),List()),None)),Splits(Set()),Empty,None,List(),List(),ToolCatalog(CompilerTools(4.17.3,2.5.2),JsTools(1.23.0,2.13.18,3.10.1,1.7.0,1.1.1,0.1.3,Fast),NativeTools(0.5.13-20261122-fa4437d-SNAPSHOT,3.10.1),FormatTools(3.11.5,2.13.18)),RunnerTools(None,None,None,None,Set(Firefox),None),OrganizationFacts(None,None,None,None,None,None,None,None),Rebuild,false,Solve,Off,CiSettings(Map(),Map(),Set(),List(),Set(),Unbounded),SupplyChain(supply-chain,Map(),AdvisoryPolicy(Threshold(High,Low),All,ByEvent(Cached(24),FailClosed,FailClosed),ReasonAndExpiry(90),List(),Off,Issue(histos-advisory),List(Osv)),UpdatePolicy(Schedule(0 6 * * 1,America/Chicago),histos/deps,OnePr(PerKind),Actions,ApiSigned,VersionPolicy(After(3),Skip,ListOnly,MinorIsMinor),Set(Libraries, Actions, Tools, Launcher),CommentOnly),OutOfBand(histos/security,Smallest,Off),ParentThenForce(WhenParentCatchesUp),OnPushToDefault(dependency-snapshot),PreflightPlusWorkflowJob),Off,CoverageExcludes(List(),List()),Off,List(),Remote,Theme(Some(Style(Cyan,Plain)),Some(Style(Cyan,Plain)),Some(Style(Cyan,Dim)),Some(Style(Cyan,Dim)),Some(Style(Green,Plain)),Some(Style(Red,Plain)),Some(Style(Yellow,Plain)),Some(Style(Yellow,Plain)),Some(Style(Yellow,Plain)),Some(Style(Red,Plain)),Some(Style(Green,Bold)),Some(Style(Red,Bold))),Inherit,List(),None)

Native libraries

A Native module links the libraries you name. link takes Ssl, Crypto, Gc, Unwind, or Stdcxx. You do not write a linker flag. On macOS, Ssl and Crypto use Homebrew OpenSSL when /opt/homebrew/opt/openssl@3 is installed. On Linux they are the system libraries, and the generated native job installs them.

A second link replaces the set. A module that builds no Native code cannot call it.

val core = module("core", Jvm, Native)(scala"3.8.1")
  .clang(ClangMajor(21))
  .link(NativeLibrary.Ssl, NativeLibrary.Crypto)
histos.NativeLibrary.token
def token: String = this match
    case Ssl    => "ssl"
    case Crypto => "crypto"
    case Gc     => "gc"
    case Unwind => "unwind"
    case Stdcxx => "stdcxx"

How many steps run at once

Compile, publish, and forked programs each have their own pool. A pool has one permit per core, so a compile does not wait on a publish, and a small machine does not start more of one class than it has cores.

Projects.parallelism sets a ceiling on every pool. Projects.parallelism(2) runs at most two of each, and one of each on a machine with a single core. Leaving it out keeps the core count. A second call replaces the ceiling. Zero and a negative number fail when the graph is built.

Projects.parallelism(2)
histos.Projects.parallelism
  /** Caps each resource class. Omission is one permit per core. A second call replaces the ceiling. `max` is at least 1.
    */
  def parallelism(max: Int): Organized = Organized.empty.parallelism(max)

What this repository builds

This repository is itself a Histos build. object build extends HistosBuild in histos.scala returns the graph. The ship lists the modules that are published, and it names two roles: histos, declared with ship.parent, is the launcher people run, with its sources in app/, and client is the optional native client. Reading that file is the example. The manual does not keep a second copy of the version numbers.

histos.ShipDef
/** A ship as written, before [[Projects]] checks names and membership. The number is the next release. */
final case class ShipDef private (
    name: String,
    number: ShipNumber,
    members: ::[ProjectDef],
    position: SourcePos,
    description: Option[PomText] = None,
    url: Option[MetadataUri] = None,
    private[histos] val toolchainAsk: Option[ToolchainAsk] = None,
):
  /** Replaces the organization description for members without their own description. */