Skip to content

Commit

Permalink
Merge pull request #1296 from lf-lang/rust-submodule
Browse files Browse the repository at this point in the history
Include reactor-rs as a submodule
  • Loading branch information
cmnrd authored Jul 18, 2022
2 parents 3904ee7 + 64a0b8a commit c52ae83
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 48 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [email protected]:lf-lang/reactor-rs.git
21 changes: 0 additions & 21 deletions bin/update-rust-runtime.sh

This file was deleted.

1 change: 1 addition & 0 deletions org.lflang/src/lib/rs/reactor-rs
Submodule reactor-rs added at a2b9da
11 changes: 0 additions & 11 deletions org.lflang/src/org/lflang/generator/rust/README.md

This file was deleted.

15 changes: 14 additions & 1 deletion org.lflang/src/org/lflang/generator/rust/RustGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand All @@ -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<Path, CodeMap> = RustEmitter.generateRustProject(fileConfig, gen)

if (targetConfig.noCompile || errorsOccurred()) {
Expand Down
23 changes: 9 additions & 14 deletions org.lflang/src/org/lflang/generator/rust/RustModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -409,22 +409,18 @@ 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<Reactor>, errorReporter: ErrorReporter): GenerationInfo {
fun makeGenerationInfo(targetConfig: TargetConfig, fileConfig: RustFileConfig, reactors: List<Reactor>, 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()


val dependencies = targetConfig.rust.cargoDependencies.toMutableMap()
dependencies.compute(RustEmitterBase.runtimeCrateFullName) { _, spec ->
computeDefaultRuntimeConfiguration(spec, targetConfig, errorReporter)
computeDefaultRuntimeConfiguration(spec, targetConfig, fileConfig, errorReporter)
}

return GenerationInfo(
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down

This file was deleted.

0 comments on commit c52ae83

Please sign in to comment.