Quick Start Guide¶
Document built: Oct 13, 2023
Requirements¶
Java 8 or newer
LLVM/Clang 15 or newer
sbt
Project Structure Overview¶
Project suffix¶
Most projects in ScalaNative cross-build against Scala 2.12, 2.13 and 3, and these projects have a suffix like 2_12, 2_13 or 3 to differentiate the Scala version.
For example, sandbox has sandbox2_12, sandbox2_13 and sandbox3.
In the following we will use suffix 3, but remember that you can build and test for different versions using different suffixes.
Build / Manual Testing on Sandbox¶
sandbox3/run to compile, link and run the main method of the sandbox project defined in sandbox/src/main/scala/Test.scala.
It’s convenient to run the sandbox project to verify the build works as expected.
Test¶
Common Test Commands
tests3/test- run the unit tests for libraries on native buildtests3/testOnly org.scalanative.testsuite.javalib.util.RandomTest- run only the test of interesttests3/testOnly *.RandomTest- run only the test of interest using wildcardtestsExt3/test- run the unit tests on native build, this module contains tests that requires dummy javalib implementation defined injavalibExtDummies.nirJVM3/test- run the unit tests for NIRtoolsJVM3/test- run the unit tests of the tools: ScalaNative backendsbtScalaNative/scripted- run all scripted tests of the sbt plugin (this takes a while).sbtScalaNative/scripted <test directory to run>- run specific scripted tests of the sbt plugin. e.g.sbtScalaNative/scripted run/backtraceScripted tests are used when you need to interact with the file system, networking, or the build system that cannot be done with a unit test.
set ThisBuild / scriptedBufferLog := falsedisables buffer log in scripted test and get more verbose output
Other Test Commands
testsJVM3/test- runtests3/teston JVMtestsExtJVM3/test- runtestsExt3/teston JVMtest-all- run all tests, ideally afterreloadandclean
Some additional tips
If you modify the
nscplugin, you will need tocleanthe project that you want to rebuild with its new version (typicallysandbox/cleanortests/clean). For a full rebuild, use the globalcleancommand.If you modify the sbt plugin or any of its transitive dependencies (
sbt-scala-native,nir,util,tools,test-runner), you will need toreloadfor your changes to take effect with most test commands (except with thescriptedtests).For a completely clean build, from scratch, run
reloadandclean.
Formatting¶
./scripts/scalafmt- format all Scala codes./scripts/clangfmt- format all C/C++ codes
Publish Locally¶
publish-local-dev x.y.z publishes the ScalaNative artifact and sbt plugin for specified scala version locally.
For example, publish-local-dev 3.3.1,
You will see, the log message like the following, which means you have successfully published locally for the version 0.5.0-SNAPSHOT.
[info] published tools_native0.5.0-SNAPSHOT_3 to ...
[info] published ivy to ...tools_native0.5.0-SNAPSHOT_3/0.5.0-SNAPSHOT/ivys/ivy.xml
Then you’ll be able to use locally published version in other projects.
# project/plugins.sbt
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.5.0-SNAPSHOT")
# build.sbt
scalaVersion := "3.3.1" # set to locally published version
enablePlugins(ScalaNativePlugin)
Locally build docs¶
First time building the docs. This command will setup & build the docs.
$ bash scripts/makedocs setup
If setup is already done. This command will only build the docs assuming setup is already done.
$ bash scripts/makedocs
Navigate to
docs/_build/htmldirectory and openindex.htmlfile in your browser.
Configure Native Build¶
To configure the native build in this project, you can edit project/MyScalaNativePlugin.scala instead of project/Build.scala.
MyScalaNativePlugin is a custom sbt plugin that extends ScalaNativePlugin and overrides some of its settings for this project.
Further Information¶
How to make a commit and PR Contributing guidelines
More detailed build setting explanation Guide to the sbt build
- Scala Native Internal
How to setup IDEs IDE setup