Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from Rust nightly to Rust stable #1218

Merged
merged 11 commits into from
Jul 29, 2022
5 changes: 0 additions & 5 deletions org.lflang/src/org/lflang/generator/rust/RustEmitter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ object RustEmitter : RustEmitterBase() {
}
}

// this file determines the default toolchain for Cargo, useful for CLion too
fileConfig.emit(codeMaps, "rust-toolchain") {
this += "nightly"
}

// if singleFile, this file will contain every module.
fileConfig.emit(codeMaps, "src/main.rs") {
with(RustMainFileEmitter) {
Expand Down
23 changes: 14 additions & 9 deletions 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 java.io.IOException
import java.nio.file.Files
import java.nio.file.Path

Expand Down Expand Up @@ -91,13 +92,7 @@ class RustGenerator(
private fun invokeRustCompiler(context: LFGeneratorContext, executableName: String, codeMaps: Map<Path, CodeMap>) {

val args = mutableListOf<String>().apply {
this += listOf(
"+nightly",
"build",
// note that this option is unstable for now and requires rust nightly ...
"--out-dir", fileConfig.binPath.toAbsolutePath().toString(),
"-Z", "unstable-options", // ... and that feature flag
)
this += "build"

val buildType = targetConfig.rust.buildType
if (buildType == BuildType.RELEASE) {
Expand All @@ -107,7 +102,6 @@ class RustGenerator(
this += buildType.cargoProfileName
}


if (targetConfig.rust.cargoFeatures.isNotEmpty()) {
this += "--features"
this += targetConfig.rust.cargoFeatures.joinWithCommas()
Expand All @@ -127,6 +121,18 @@ class RustGenerator(
val cargoReturnCode = RustValidator(fileConfig, errorReporter, codeMaps).run(cargoCommand, context.cancelIndicator)

if (cargoReturnCode == 0) {
// We still have to copy the compiled binary to the destination folder.
val buildType = targetConfig.rust.buildType
var binaryPath = fileConfig.srcGenPath
.resolve("target")
.resolve(buildType.cargoProfileName)
.resolve(executableName)
val destFile = fileConfig.binPath.resolve(executableName).toFile()
val binaryFile = binaryPath.toFile()
binaryFile.copyTo(destFile, overwrite = true)
// Files do not retain permissions when copied.
destFile.setExecutable(true)

println("SUCCESS (compiling generated Rust code)")
println("Generated source code is in ${fileConfig.srcGenPath}")
println("Compiled binary is in ${fileConfig.binPath}")
Expand All @@ -141,7 +147,6 @@ class RustGenerator(
}
}


override fun getTarget(): Target = Target.Rust

override fun getTargetTypes(): TargetTypes = RustTypes
Expand Down
2 changes: 1 addition & 1 deletion org.lflang/src/org/lflang/generator/rust/RustModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ private val TypeParm.identifier: String
*/
val BuildType.cargoProfileName: String
get() = when (this) {
BuildType.DEBUG -> "dev"
BuildType.DEBUG -> "debug"
BuildType.RELEASE -> "release"
BuildType.REL_WITH_DEB_INFO -> "release-with-debug-info"
BuildType.MIN_SIZE_REL -> "release-with-min-size"
Expand Down