Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai c00016db8a fix(plugins): load precompiled plugin components in the signed macOS app
compile_cached loaded the cached .cwasm with Component::deserialize_file,
which maps the file and makes its pages executable. The hardened runtime
of the signed app refuses that ("unable to make memory executable:
Permission denied"), so every activation logged "discarding precompiled
... failed to load code", deleted the cache file and compiled the plugin
again. The file is now read into memory and deserialized from the bytes,
which wasmtime copies into memory the app may make executable.

Refs #6954
2026-11-30 18:16:10 +08:00
+25 -2
Переглянути файл
@@ -613,11 +613,14 @@ impl PluginEngine {
pub fn compile_cached(&self, wasm: &Path, cache_dir: &Path) -> Result<Component, String> {
let bytes = std::fs::read(wasm).map_err(|e| format!("{}: {e}", wasm.display()))?;
let file = cache_dir.join(format!("{}.cwasm", self.cache_key(&bytes)));
if file.is_file() {
// Read into memory rather than `deserialize_file`: that maps the file and makes its pages
// executable, which the hardened runtime of the signed macOS app refuses ("failed to make
// memory executable"), so the cache never hit and every activation compiled again.
if let Ok(precompiled) = std::fs::read(&file) {
// SAFETY: the cache directory belongs to the IDE (inside its plugins
// directory) and is written only by `store_precompiled` below from
// components this engine compiled; a corrupt file fails validation.
match unsafe { Component::deserialize_file(&self.engine, &file) } {
match unsafe { Component::deserialize(&self.engine, &precompiled) } {
Ok(component) => return Ok(component),
Err(e) => {
tracing::info!("discarding precompiled {}: {e}", file.display());
@@ -3035,6 +3038,26 @@ impl Runtime {
mod tests {
use super::*;
/// The second compile of the same component loads the cached one instead of compiling and
/// writing it again (a failed load deletes and rewrites the file).
#[test]
fn a_precompiled_component_is_loaded_from_the_cache() {
let engine = PluginEngine::new().unwrap();
let wasm = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/hello/dist/plugin.wasm");
let cache = tempfile::tempdir().unwrap();
engine.compile_cached(&wasm, cache.path()).unwrap();
let cached = || {
let entries: Vec<_> = std::fs::read_dir(cache.path()).unwrap().flatten().map(|e| e.path()).collect();
assert_eq!(entries.len(), 1, "{entries:?}");
let file = entries[0].clone();
(std::fs::metadata(&file).unwrap().modified().unwrap(), file)
};
let before = cached();
std::thread::sleep(std::time::Duration::from_millis(20));
engine.compile_cached(&wasm, cache.path()).unwrap();
assert_eq!(cached(), before, "loaded, not compiled and stored again");
}
#[test]
fn readonly_field_extensions_are_parsed_and_unknown_or_malformed_fields_are_skipped() {
let fields = [