Skip to content

Add native tooling/runtime deps to export --json#4240

Draft
kubukoz wants to merge 9 commits into
VirtusLab:mainfrom
kubukoz:native-export-options
Draft

Add native tooling/runtime deps to export --json#4240
kubukoz wants to merge 9 commits into
VirtusLab:mainfrom
kubukoz:native-export-options

Conversation

@kubukoz
Copy link
Copy Markdown
Contributor

@kubukoz kubukoz commented Apr 18, 2026

Summary

  • Adds a nativeOptions field to export --json output when platform == "Native", containing:
    • scalaNativeVersion — the effective Scala Native version
    • compilerPlugins — implicit compiler plugins (e.g. nscplugin)
    • runtimeDependencies — implicit runtime deps (e.g. javalib, scala3lib)
    • toolingDependencies — packaging-time deps (e.g. scala-native-cli)
  • Existing top-level fields (scalaNativeVersion, platform, etc.) are unchanged for backward compatibility
  • Non-Native exports (JVM, JS) are unaffected — nativeOptions is absent

Closes #4234

Motivation

Downstream tools like scala-cli-nix need to know the full artifact closure used by scala-cli package to prefetch dependencies for offline builds. Previously, export --json only exposed user-declared dependencies, forcing downstream tools to hardcode knowledge of Scala CLI internals (implicit Native runtime/tooling deps).

Example output

{
  "scalaNativeVersion": "0.5.10",
  "nativeOptions": {
    "scalaNativeVersion": "0.5.10",
    "compilerPlugins": [
      { "groupId": "org.scala-native", "artifactId": { "name": "nscplugin", "fullName": "nscplugin_3.2.2" }, "version": "0.5.10" }
    ],
    "runtimeDependencies": [
      { "groupId": "org.scala-native", "artifactId": { "name": "javalib_native0.5", "fullName": "javalib_native0.5_3" }, "version": "0.5.10" },
      { "groupId": "org.scala-native", "artifactId": { "name": "scala3lib_native0.5", "fullName": "scala3lib_native0.5_3" }, "version": "3.2.2+0.5.10" }
    ],
    "toolingDependencies": [
      { "groupId": "org.scala-native", "artifactId": { "name": "scala-native-cli", "fullName": "scala-native-cli_2.12" }, "version": "0.5.10" }
    ]
  }
}

Test plan

  • Existing export json with test scope integration test updated with expected nativeOptions
  • JVM and JS exports verified to not include nativeOptions
  • Manually tested native binary output against a Scala Native project

🤖 Generated with Claude Code

@kubukoz kubukoz force-pushed the native-export-options branch from 908f327 to aa81e1e Compare April 18, 2026 23:13
|"scalaNativeVersion":"${Constants.scalaNativeVersion}",
|"scalaNativeVersion":"$nativeVersion",
|"nativeOptions": {
| "scalaNativeVersion":"$nativeVersion",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: this is duplicated

@kubukoz kubukoz marked this pull request as draft April 20, 2026 11:40
@kubukoz
Copy link
Copy Markdown
Contributor Author

kubukoz commented Apr 20, 2026

I need to test this out a bit more :)

@kubukoz kubukoz force-pushed the native-export-options branch 3 times, most recently from 4689941 to c08b786 Compare May 7, 2026 23:13
kubukoz added 7 commits May 15, 2026 19:14
The runner is added inside Artifacts.apply (gated on addJvmTestRunner) -
after BuildInfo has been materialized, so export --json reported only
user-declared test deps. Extract the runner-version selection (with
legacy fallbacks for old Scala/Java) into a shared helper and call it
from ScopedSources.getScopedBuildInfo and JsonProjectDescriptor.export
so the test scope's dependencies reflect what scala-cli would resolve
at test time. Injection is gated on scope == Test, non-empty sources,
JVM platform, and a Scala (non-Java-only) build, mirroring Artifacts.
Only inject the JVM test-runner dependency into the Test scope when
generating BuildInfo for export --json. The runtime BuildInfo.scala
generator (ScopedSources.buildInfo) must not inject it: scala-cli
supplies the test-runner at runtime, so users' BuildInfo.Test.dependencies
would otherwise contain a dep they never declared, breaking
RunTestsDefault."BuildInfo fields should be reachable".
@kubukoz kubukoz force-pushed the native-export-options branch from 525a585 to e9c581b Compare May 15, 2026 17:14
kubukoz and others added 2 commits May 15, 2026 22:54
scala-cli builds the main and test scopes as two separate Build objects,
each running its own Coursier resolution. Downstream tools that need to
reproduce that resolution (e.g. lockfile generators) have to re-derive
which direct deps scala-cli injects per scope — JVM test-runner, Scala
Native runtime libs, Native test-interface, JS test-bridge — and the
conditions under which it does so. The export today only surfaces the
runtime-deps slice via the top-level nativeOptions, leaving consumers
to guess the rest.

Add a per-scope `injectedDependencies` field to ScopedBuildInfo,
populated by `export --json` (always false in the runtime BuildInfo.scala
generator). It mirrors what `Artifacts.apply` adds beyond user-declared
deps for each scope:

- Native: javalib_native + scala3lib_native/scalalib_native + nscplugin
  for both Main and Test
- JS: scalajs-library + scalajs-compiler (Scala 2) for both Main and Test
- JVM Test: test-runner_<scalaBinary> (already in dependencies via
  earlier commit; moved here for consistency)
- Native Test: test-interface_native<snBinary>_<scalaBinary>
- JS Test: scalajs-test-bridge

Document the two-scope-two-resolutions model in the forScope scaladoc so
consumers know each scope's resolution can produce a different transitive
winner.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
These fields were introduced in "Include Native tools and deps in export
--json" to surface the Scala Native runtime libs and `nscplugin` for
downstream consumers. The follow-up "Expose per-scope injected deps in
export --json" now reports the same artifacts per scope under
`scopes.<scope>.injectedDependencies`, making the top-level copy
redundant. Drop the two fields from `NativeOptionsInfo` and stop
populating them in `BuildInfo.scalaNativeSettings`. `toolingDependencies`
stays — `scala-native-cli` is shared across scopes and doesn't fit the
per-scope `injectedDependencies` model.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

export --json: Provide tooling versions (e.g. Native CLI)

1 participant