From 414be4fed27c0801f83ac18fdc53463837119010 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 14 Jul 2022 10:34:30 +0200 Subject: [PATCH 1/5] add reactor-rs as a submodule --- .gitmodules | 3 +++ org.lflang/src/lib/rs/reactor-rs | 1 + 2 files changed, 4 insertions(+) create mode 160000 org.lflang/src/lib/rs/reactor-rs 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/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 From 14de31e2560347bc3190f43d56fea9b8f5441659 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 14 Jul 2022 10:57:20 +0200 Subject: [PATCH 2/5] refer to local reactor-rs path --- .../lflang/generator/rust/RustEmitterBase.kt | 1 + .../src/org/lflang/generator/rust/RustModel.kt | 17 +++++------------ .../generator/rust/rust-runtime-version.txt | 1 - 3 files changed, 6 insertions(+), 13 deletions(-) delete mode 100644 org.lflang/src/org/lflang/generator/rust/rust-runtime-version.txt diff --git a/org.lflang/src/org/lflang/generator/rust/RustEmitterBase.kt b/org.lflang/src/org/lflang/generator/rust/RustEmitterBase.kt index 0ba355de2a..d2b976c01c 100644 --- a/org.lflang/src/org/lflang/generator/rust/RustEmitterBase.kt +++ b/org.lflang/src/org/lflang/generator/rust/RustEmitterBase.kt @@ -63,6 +63,7 @@ abstract class RustEmitterBase { /** Name of the runtime crate that is in its Cargo.toml.*/ const val runtimeCrateFullName = "reactor_rt" const val runtimeGitUrl = "https://github.com/lf-lang/reactor-rust.git" + const val runtimeLocalPath = "../reactor-rs" /** Qualification prefix to refer to a member of the runtime library crate. */ const val rsRuntime = "::$runtimeCrateFullName" diff --git a/org.lflang/src/org/lflang/generator/rust/RustModel.kt b/org.lflang/src/org/lflang/generator/rust/RustModel.kt index 8fd0340ca7..4a9bc3b672 100644 --- a/org.lflang/src/org/lflang/generator/rust/RustModel.kt +++ b/org.lflang/src/org/lflang/generator/rust/RustModel.kt @@ -409,10 +409,6 @@ 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. */ @@ -462,26 +458,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 = RustEmitterBase.runtimeLocalPath } 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 = RustEmitterBase.runtimeLocalPath } // 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 From 4eef373a617b1c60e31529834ba3d249efc57cb0 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 14 Jul 2022 14:15:44 +0200 Subject: [PATCH 3/5] copy reactor-rs from the classpath --- .../lflang/generator/rust/RustCargoTomlEmitter.kt | 2 +- .../src/org/lflang/generator/rust/RustGenerator.kt | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/rust/RustCargoTomlEmitter.kt b/org.lflang/src/org/lflang/generator/rust/RustCargoTomlEmitter.kt index c4ef1b8a16..044522e1ab 100644 --- a/org.lflang/src/org/lflang/generator/rust/RustCargoTomlEmitter.kt +++ b/org.lflang/src/org/lflang/generator/rust/RustCargoTomlEmitter.kt @@ -79,7 +79,7 @@ ${" |"..crate.dependencies.asIterable().joinToString("\n") { (name, spec private fun CargoDependencySpec.toToml(): String = mutableMapOf().apply { if (version != null) this["version"] = version.asStringLiteral() - if (localPath != null) this["path"] = Paths.get(localPath).toAbsolutePath().toString().asStringLiteral() + if (localPath != null) this["path"] = Paths.get(localPath).toString().asStringLiteral() if (features != null) this["features"] = features.map { it.asStringLiteral() }.joinWithCommas("[", "]") if (gitRepo != null) this["git"] = gitRepo.asStringLiteral() if (rev != null) this["rev"] = rev.asStringLiteral() diff --git a/org.lflang/src/org/lflang/generator/rust/RustGenerator.kt b/org.lflang/src/org/lflang/generator/rust/RustGenerator.kt index 1032a03e51..46a74f005b 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,6 +78,12 @@ class RustGenerator( Files.createDirectories(fileConfig.srcGenPath) + FileUtil.copyDirectoryFromClassPath( + runtimeDir, + fileConfig.srcGenBasePath.resolve(runtimeName), + true + ) + val gen = RustModelBuilder.makeGenerationInfo(targetConfig, reactors, errorReporter) val codeMaps: Map = RustEmitter.generateRustProject(fileConfig, gen) From 57acfaf4f0026d065f5f57ae827ad6fbdfe478b7 Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 14 Jul 2022 14:16:27 +0200 Subject: [PATCH 4/5] delete update-rust-runtime script and outdated readme --- bin/update-rust-runtime.sh | 21 ------------------- .../src/org/lflang/generator/rust/README.md | 11 ---------- 2 files changed, 32 deletions(-) delete mode 100755 bin/update-rust-runtime.sh delete mode 100644 org.lflang/src/org/lflang/generator/rust/README.md 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/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. From 64a0b8aa95c61b2731ec252ec69e26512f2647ee Mon Sep 17 00:00:00 2001 From: Christian Menard Date: Thu, 14 Jul 2022 17:05:44 +0200 Subject: [PATCH 5/5] use absolute paths --- .../org/lflang/generator/rust/RustCargoTomlEmitter.kt | 2 +- .../src/org/lflang/generator/rust/RustEmitterBase.kt | 1 - .../src/org/lflang/generator/rust/RustGenerator.kt | 2 +- org.lflang/src/org/lflang/generator/rust/RustModel.kt | 10 ++++++---- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/rust/RustCargoTomlEmitter.kt b/org.lflang/src/org/lflang/generator/rust/RustCargoTomlEmitter.kt index 044522e1ab..c4ef1b8a16 100644 --- a/org.lflang/src/org/lflang/generator/rust/RustCargoTomlEmitter.kt +++ b/org.lflang/src/org/lflang/generator/rust/RustCargoTomlEmitter.kt @@ -79,7 +79,7 @@ ${" |"..crate.dependencies.asIterable().joinToString("\n") { (name, spec private fun CargoDependencySpec.toToml(): String = mutableMapOf().apply { if (version != null) this["version"] = version.asStringLiteral() - if (localPath != null) this["path"] = Paths.get(localPath).toString().asStringLiteral() + if (localPath != null) this["path"] = Paths.get(localPath).toAbsolutePath().toString().asStringLiteral() if (features != null) this["features"] = features.map { it.asStringLiteral() }.joinWithCommas("[", "]") if (gitRepo != null) this["git"] = gitRepo.asStringLiteral() if (rev != null) this["rev"] = rev.asStringLiteral() diff --git a/org.lflang/src/org/lflang/generator/rust/RustEmitterBase.kt b/org.lflang/src/org/lflang/generator/rust/RustEmitterBase.kt index d2b976c01c..0ba355de2a 100644 --- a/org.lflang/src/org/lflang/generator/rust/RustEmitterBase.kt +++ b/org.lflang/src/org/lflang/generator/rust/RustEmitterBase.kt @@ -63,7 +63,6 @@ abstract class RustEmitterBase { /** Name of the runtime crate that is in its Cargo.toml.*/ const val runtimeCrateFullName = "reactor_rt" const val runtimeGitUrl = "https://github.com/lf-lang/reactor-rust.git" - const val runtimeLocalPath = "../reactor-rs" /** Qualification prefix to refer to a member of the runtime library crate. */ const val rsRuntime = "::$runtimeCrateFullName" diff --git a/org.lflang/src/org/lflang/generator/rust/RustGenerator.kt b/org.lflang/src/org/lflang/generator/rust/RustGenerator.kt index 46a74f005b..cb30d63a57 100644 --- a/org.lflang/src/org/lflang/generator/rust/RustGenerator.kt +++ b/org.lflang/src/org/lflang/generator/rust/RustGenerator.kt @@ -84,7 +84,7 @@ class RustGenerator( true ) - val gen = RustModelBuilder.makeGenerationInfo(targetConfig, reactors, errorReporter) + 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 4a9bc3b672..03ffafa768 100644 --- a/org.lflang/src/org/lflang/generator/rust/RustModel.kt +++ b/org.lflang/src/org/lflang/generator/rust/RustModel.kt @@ -412,7 +412,7 @@ object RustModelBuilder { /** * 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() @@ -420,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( @@ -448,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 @@ -467,14 +469,14 @@ object RustModelBuilder { spec.gitRepo = RustEmitterBase.runtimeGitUrl spec.rev = userRtVersion } else { - spec.localPath = RustEmitterBase.runtimeLocalPath + spec.localPath = defaultRuntimePath } return spec } else { if (userSpec.localPath == null && userSpec.gitRepo == null) { // default the location - userSpec.localPath = RustEmitterBase.runtimeLocalPath + userSpec.localPath = defaultRuntimePath } // override location