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

Rust 1.79 #4

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ jobs:
ORG_GRADLE_PROJECT_compileNativeCode: false
DEFAULT_EDITION_FOR_TESTS: ${{ matrix.default-edition-for-tests }}
EVCXR_REPL_VERSION: 0.17.0
CARGO_GENERATE_VERSION: 0.15.2
CARGO_GENERATE_VERSION: 0.21.3

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -156,8 +156,8 @@ jobs:
args: evcxr_repl --locked --version ${{ env.EVCXR_REPL_VERSION }}

- name: Install cargo-generate
# BACKCOMPAT: cargo-generate 0.15.2 requires Rust 1.61.0 or newer
if: matrix.rust-version >= '1.61.0'
# BACKCOMPAT: cargo-generate 0.21.3 requires Rust 1.74.0 or newer
if: matrix.rust-version >= '1.74.0'
uses: actions-rs/cargo@v1
with:
command: install
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/get-rust-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ on:
value: ${{ jobs.get_versions.outputs.matrix }}

env:
STABLE: "1.74.0"
NIGHTLY: "nightly-2023-11-16"
STABLE: "1.79.0"
NIGHTLY: "nightly-2024-06-13"
OLD: "1.56.0"

jobs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,62 @@ package org.rust.cargo.project.workspace

import org.rust.cargo.CfgOptions
import org.rust.cargo.toolchain.impl.CargoMetadata
import org.rust.cargo.util.parseSemVer
import org.rust.stdext.HashCode
import java.net.URL
import java.nio.file.Path

typealias PackageId = String

/** Refers to [Package ID specification](https://doc.rust-lang.org/cargo/reference/pkgid-spec.html) */
data class PackageIdSpec(
val name: String,
val version: String?,
) {
companion object {
fun parse(spec: String): PackageIdSpec {
if (spec.contains("://")) {
val url = "http://" + spec.split("://", limit = 2)[1]
return fromUrl(URL(url))
}
val parts = spec.split(':', '@', limit = 2)

return if (parts.size > 1) {
PackageIdSpec(parts[0], parts[1])
} else {
PackageIdSpec(parts[0], null)
}
}

private fun fromUrl(url: URL): PackageIdSpec {
val frag: String? = url.ref
val pathName = url.path.substringAfterLast("/")

if (frag == null || frag == "") {
return PackageIdSpec(pathName, null)
}

val parts = frag.split(':', '@', limit = 2)

return if (parts.size > 1) {
// name ("@" | ":" ) semver
PackageIdSpec(parts[0], parts[1])
} else {
// ( name | semver )
val first = frag[0]
if (first.isLetter() || first == '_') {
// A valid package name starts with a letter or `_`.
// https://github.com/rust-lang/cargo/blob/master/crates/cargo-util-schemas/src/restricted_names.rs#L64
PackageIdSpec(frag, null)
} else {
frag.parseSemVer()
PackageIdSpec(pathName, frag)
}
}
}
}
}

/** Refers to [org.rust.cargo.project.workspace.PackageImpl.rootDirectory] */
typealias PackageRoot = Path

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.intellij.openapi.util.NlsSafe
import com.intellij.openapi.util.text.StringUtil
import org.jetbrains.annotations.Nls
import org.rust.RsBundle
import org.rust.cargo.project.workspace.PackageIdSpec
import org.rust.cargo.runconfig.RsAnsiEscapeDecoder.Companion.quantizeAnsiColors
import org.rust.cargo.runconfig.removeEscapeSequences
import org.rust.cargo.toolchain.impl.CargoMetadata
Expand Down Expand Up @@ -73,7 +74,25 @@ class RsBuildEventsConverter(private val context: CargoBuildContextBase) : Build
val message = rustcMessage.message.trim().capitalized().trimEnd('.')
if (message.startsWith("Aborting due") || message.endsWith("emitted")) return true

val parentEventId = topMessage.package_id.substringBefore("(").trimEnd()
val packageId = topMessage.package_id
val parentEventId = if (packageId.endsWith(")")) {
// BACKCOMPAT: Rust 1.77.
// Cargo 1.77 stabilized a new package identifier format.
// https://github.com/rust-lang/cargo/blob/5046f25d05310805d62cc7b46b7ffcf27166334e/CHANGELOG.md#cargo-177-2024-03-21
// https://github.com/rust-lang/cargo/commit/77f2da7b926008b7edcca2fcf6bf1ed4eee56872
packageId.substringBefore("(").trimEnd()
} else {
try {
val spec = PackageIdSpec.parse(packageId)
if (spec.version != null) {
"${spec.name} ${spec.version}"
} else {
spec.name
}
} catch (_: Exception) {
packageId
}
}

val kind = getMessageKind(rustcMessage.level)
if (kind == MessageEvent.Kind.SIMPLE) return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ enum class ProMacroExpanderVersion {
NO_VERSION_CHECK_VERSION,
VERSION_CHECK_VERSION,
ENCODE_CLOSE_SPAN_VERSION,
HAS_GLOBAL_SPANS,
RUST_ANALYZER_SPAN_SUPPORT,
;

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ class ProcMacroExpander private constructor(
remoteLib,
envMapped.map { listOf(it.key, it.value) },
envMapped["CARGO_MANIFEST_DIR"],
Request.ExpnGlobals(0, -1, 0),
null,
)
val response = server.send(request, timeout).unwrapOrElse { return Err(it.toProcMacroExpansionError()) }
check(response is Response.ExpandMacro)
Expand Down
22 changes: 22 additions & 0 deletions src/main/kotlin/org/rust/lang/core/macros/proc/Request.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package org.rust.lang.core.macros.proc

import com.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.databind.SerializerProvider
import it.unimi.dsi.fastutil.ints.IntArrayList
import org.rust.lang.core.macros.tt.FlatTree
import org.rust.lang.core.macros.tt.FlatTreeJsonSerializer
import org.rust.util.RsJacksonSerializer
Expand All @@ -21,8 +22,19 @@ sealed class Request {
val lib: String,
val env: List<List<String>>,
val currentDir: String?,
val hasGlobalSpans: ExpnGlobals,
val spanDataTable: IntArrayList?,
) : Request()

/**
* See https://github.com/rust-lang/rust-analyzer/blob/5761b50ed899ca9c9ba9cab672d30b68725b3c18/crates/proc-macro-api/src/msg.rs#L108
*/
data class ExpnGlobals(
val defSite: Int,
val callSite: Int,
val mixedSite: Int,
)

object ApiVersionCheck : Request()
}

Expand All @@ -41,6 +53,16 @@ class RequestJsonSerializer : RsJacksonSerializer<Request>(Request::class.java)
writeArray(list) { writeString(it) }
}
writeStringField("current_dir", request.currentDir)
writeField("has_global_spans") {
writeJsonObject {
writeNumberField("def_site", request.hasGlobalSpans.defSite.toLong() and 0xFFFFFFFFL)
writeNumberField("call_site", request.hasGlobalSpans.callSite.toLong() and 0xFFFFFFFFL)
writeNumberField("mixed_site", request.hasGlobalSpans.mixedSite.toLong() and 0xFFFFFFFFL)
}
}
if (request.spanDataTable != null) {
writeArrayField("span_data_table", request.spanDataTable) { writeNumber(it.toLong() and 0xFFFFFFFFL) }
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/org/rust/lang/core/psi/BuiltinAttributes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const val RS_BUILTIN_ATTRIBUTES_VERSION: Int = 1

val RS_BUILTIN_ATTRIBUTES: Map<String, AttributeInfo> = BuiltinAttributeInfoLoader.loadAttributes()

// https://github.com/rust-lang/rust/blob/76d18cfb8945f824c8777e04981e930d2037954e/compiler/rustc_resolve/src/macros.rs#L153
val RS_BUILTIN_TOOL_ATTRIBUTES = setOf("rustfmt", "clippy")
// https://github.com/rust-lang/rust/blob/3954398882707ce3f683722795d1a7111312b5d9/compiler/rustc_resolve/src/macros.rs#L149
val RS_BUILTIN_TOOL_ATTRIBUTES = setOf("rustfmt", "clippy", "diagnostic", "miri", "rust_analyzer")

sealed interface AttributeInfo

Expand Down
Loading