diff --git a/.gitmodules b/.gitmodules index d0c0026657..8f1d2f5149 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "org.lflang/src/lib/cpp/reactor-cpp"] path = org.lflang/src/lib/cpp/reactor-cpp url = https://github.com/lf-lang/reactor-cpp +[submodule "org.lflang/src/lib/rs/reactor-rs"] + path = org.lflang/src/lib/rs/reactor-rs + url = git@github.com:lf-lang/reactor-rs.git diff --git a/bin/update-rust-runtime.sh b/bin/update-rust-runtime.sh deleted file mode 100755 index ecd7491d20..0000000000 --- a/bin/update-rust-runtime.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -# This script updates the version of the Rust runtime used by -# LFC and tested in CI. See README.md in Rust code generator -# directory. - -if [[ -z "$LOCAL_RUST_REACTOR_RT" ]]; then - echo "Set LOCAL_RUST_REACTOR_RT properly plz" - exit 1 -fi - -cd "$LOCAL_RUST_REACTOR_RT" || (echo "could not cd to $LOCAL_RUST_REACTOR_RT" && exit 1) -revision_no="$(git rev-parse HEAD)" -cd - - -# the directory of the script (LF_ROOT/bin) -script_dir="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" - - -echo "$revision_no" > "$script_dir/../org.lflang/src/org/lflang/generator/rust/rust-runtime-version.txt" - -echo "updated to $revision_no" diff --git a/org.lflang/src/lib/rs/reactor-rs b/org.lflang/src/lib/rs/reactor-rs new file mode 160000 index 0000000000..a2b9dae07b --- /dev/null +++ b/org.lflang/src/lib/rs/reactor-rs @@ -0,0 +1 @@ +Subproject commit a2b9dae07bb8568ee321cfe87226ef59151efad4 diff --git a/org.lflang/src/org/lflang/generator/rust/README.md b/org.lflang/src/org/lflang/generator/rust/README.md deleted file mode 100644 index 0d8f8d6318..0000000000 --- a/org.lflang/src/org/lflang/generator/rust/README.md +++ /dev/null @@ -1,11 +0,0 @@ -### The Rust code generator - -The runtime is hosted over at https://github.com/lf-lang/reactor-rust - -LFC generates Cargo projects that pull in this dependency using the git revision number hardcoded in `rust-runtime-version.txt`. You can override this behavior with the `--external-runtime-path` LFC option. - -To develop this package and the runtime in sync, it is recommended to clone the runtime repo and set the environment variable `LOCAL_RUST_REACTOR_RT` to the relevant path in your shell. This allows you -- to update the Rust runtime version easily with the script `bin/update-rust-runtime.sh` -- to have your local test runs always link to that local repo instead of using the hardcoded revision. This enables you to e.g. test uncommitted changes to the runtime and also debug them from within CLion. - -Note: that variable is not meant to be set in CI, ever. diff --git a/org.lflang/src/org/lflang/generator/rust/RustGenerator.kt b/org.lflang/src/org/lflang/generator/rust/RustGenerator.kt index 1032a03e51..cb30d63a57 100644 --- a/org.lflang/src/org/lflang/generator/rust/RustGenerator.kt +++ b/org.lflang/src/org/lflang/generator/rust/RustGenerator.kt @@ -39,6 +39,7 @@ import org.lflang.joinWithCommas import org.lflang.lf.Action import org.lflang.lf.VarRef import org.lflang.scoping.LFGlobalScopeProvider +import org.lflang.util.FileUtil import java.nio.file.Files import java.nio.file.Path @@ -62,6 +63,12 @@ class RustGenerator( @Suppress("UNUSED_PARAMETER") unused: LFGlobalScopeProvider ) : GeneratorBase(fileConfig, errorReporter) { + companion object { + /** Path to the rust runtime library (relative to class path) */ + const val runtimeDir = "/lib/rs/reactor-rs" + const val runtimeName = "reactor-rs" + } + override fun doGenerate(resource: Resource, context: LFGeneratorContext) { super.doGenerate(resource, context) @@ -71,7 +78,13 @@ class RustGenerator( Files.createDirectories(fileConfig.srcGenPath) - val gen = RustModelBuilder.makeGenerationInfo(targetConfig, reactors, errorReporter) + FileUtil.copyDirectoryFromClassPath( + runtimeDir, + fileConfig.srcGenBasePath.resolve(runtimeName), + true + ) + + val gen = RustModelBuilder.makeGenerationInfo(targetConfig, fileConfig, reactors, errorReporter) val codeMaps: Map = RustEmitter.generateRustProject(fileConfig, gen) if (targetConfig.noCompile || errorsOccurred()) { diff --git a/org.lflang/src/org/lflang/generator/rust/RustModel.kt b/org.lflang/src/org/lflang/generator/rust/RustModel.kt index 8fd0340ca7..03ffafa768 100644 --- a/org.lflang/src/org/lflang/generator/rust/RustModel.kt +++ b/org.lflang/src/org/lflang/generator/rust/RustModel.kt @@ -409,14 +409,10 @@ private val BLOCK_R = Regex("\\{(.*)}", RegexOption.DOT_MATCHES_ALL) */ object RustModelBuilder { - private val runtimeGitRevision = - javaClass.getResourceAsStream("rust-runtime-version.txt")!! - .bufferedReader().readLine().trim() - /** * Given the input to the generator, produce the model classes. */ - fun makeGenerationInfo(targetConfig: TargetConfig, reactors: List, errorReporter: ErrorReporter): GenerationInfo { + fun makeGenerationInfo(targetConfig: TargetConfig, fileConfig: RustFileConfig, reactors: List, errorReporter: ErrorReporter): GenerationInfo { val reactorsInfos = makeReactorInfos(reactors) // todo how do we pick the main reactor? it seems like super.doGenerate sets that field... val mainReactor = reactorsInfos.lastOrNull { it.isMain } ?: reactorsInfos.last() @@ -424,7 +420,7 @@ object RustModelBuilder { val dependencies = targetConfig.rust.cargoDependencies.toMutableMap() dependencies.compute(RustEmitterBase.runtimeCrateFullName) { _, spec -> - computeDefaultRuntimeConfiguration(spec, targetConfig, errorReporter) + computeDefaultRuntimeConfiguration(spec, targetConfig, fileConfig, errorReporter) } return GenerationInfo( @@ -452,8 +448,10 @@ object RustModelBuilder { private fun computeDefaultRuntimeConfiguration( userSpec: CargoDependencySpec?, targetConfig: TargetConfig, + fileConfig: RustFileConfig, errorReporter: ErrorReporter ): CargoDependencySpec { + val defaultRuntimePath = fileConfig.srcGenBasePath.resolve(RustGenerator.runtimeName).toString() if (userSpec == null) { // default configuration for the runtime crate @@ -462,26 +460,23 @@ object RustModelBuilder { val parallelFeature = listOf(PARALLEL_RT_FEATURE).takeIf { targetConfig.threading } val spec = newCargoSpec( - gitTag = userRtVersion?.let { "v$it" }, features = parallelFeature, ) if (targetConfig.externalRuntimePath != null) { spec.localPath = targetConfig.externalRuntimePath - } else { + } else if (userRtVersion != null){ spec.gitRepo = RustEmitterBase.runtimeGitUrl - spec.rev = runtimeGitRevision.takeIf { userRtVersion == null } + spec.rev = userRtVersion + } else { + spec.localPath = defaultRuntimePath } return spec } else { if (userSpec.localPath == null && userSpec.gitRepo == null) { // default the location - userSpec.gitRepo = RustEmitterBase.runtimeGitUrl - } - if (userSpec.version == null && userSpec.tag == null && userSpec.rev == null) { - // default the version - userSpec.rev = runtimeGitRevision + userSpec.localPath = defaultRuntimePath } // override location diff --git a/org.lflang/src/org/lflang/generator/rust/rust-runtime-version.txt b/org.lflang/src/org/lflang/generator/rust/rust-runtime-version.txt deleted file mode 100644 index fb246f1a7d..0000000000 --- a/org.lflang/src/org/lflang/generator/rust/rust-runtime-version.txt +++ /dev/null @@ -1 +0,0 @@ -50a33d73bd2fea7fcf1921fe849b1f75279ee44a