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

Add library section to generated Cargo.toml #366

Merged
merged 1 commit into from
Jan 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions crates/CrateAssembler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ class CrateAssembler : Callable<Unit> {
}

val cargoToml = TarArchiveEntry("$prefix/Cargo.toml")
val cargoTomlText = generateCargoToml().toByteArray()
val crateRootPath = "src/" + libraryRoot.relativize(crateRoot.toAbsolutePath()).toString()
val cargoTomlText = generateCargoToml(crateRootPath).toByteArray()
cargoToml.size = cargoTomlText.size.toLong()
tarOutputStream.putArchiveEntry(cargoToml)

Expand All @@ -136,7 +137,7 @@ class CrateAssembler : Callable<Unit> {
}
}

private fun generateCargoToml(): String {
private fun generateCargoToml(crateRootPath: String): String {
val cargoToml = Config.inMemory()
cargoToml.createSubConfig().apply {
cargoToml.set<Config>("package", this)
Expand All @@ -152,6 +153,10 @@ class CrateAssembler : Callable<Unit> {
set<String>("description", description)
set<String>("readme", readmeFile?.toPath()?.fileName?.toString() ?: "")
}
cargoToml.createSubConfig().apply {
cargoToml.set<Config>("lib", this)
set<String>("path", crateRootPath)
}
cargoToml.createSubConfig().apply {
cargoToml.set<Config>("dependencies", this)
depsList.associate { it.split("=").let { (dep, ver) -> dep to ver } }.forEach { (dep, ver) ->
Expand Down