char/avril
(wip) why'd you have to go and make things so complicaaaaated?
git clone https://git.t4t.associates/char/avril
f4a0f5b
main
1use std:: rc:: Rc ; 2use std:: sync:: Arc ; 3 4use avril_core::{ Op , Runtime , RuntimeOptions , Snapshot }; 5 6use super ::{ Settings , WorkerScope , extensions}; 7use crate :: authority:: SourceAuthority ; 8use crate :: caps::{ Capabilities , Initial }; 9use crate :: modules:: ModuleGraph ; 10use crate :: registry::{ Options , PackageStore }; 11use avril_ext_process:: SignalMode ; 12use avril_ext_stdio:: Stdio ; 13use avril_host:: Host ; 14use avril_host:: environment:: Environment ; 15 16# [ derive ( Debug , thiserror :: Error )] 17# [ error ( "Live operation during snapshot generation: {0}" )] 18struct LiveOp ( &' static str ); 19 20/// Generate main and worker contexts in one artifact, without ambient guest authority. 21/// Must be the first V8 use in a dedicated generator process; live runtimes are 22/// disabled in that process so the deterministic generation seed cannot reach guests. 23pub fn create () ->Result < Snapshot , Box < dyn std:: error:: Error >> { 24 avril_core:: initialize_snapshot_generator () ?; 25let directory = tempfile:: tempdir () ?; 26let root = directory. path (); 27let host =Host :: new () ?; 28let caps =Capabilities :: new ( Initial :: new ( false ), root. to_owned ()); 29let store =Arc :: new ( PackageStore :: new_with_authority ( 30 host. handle (), 31Options { 32jsr_registry : "https://jsr.invalid/" . parse () ?, 33npm_registry : "https://npm.invalid/" . parse () ?, 34cache : root. join ( "cache" ), 35lock : root. join ( "avril.lock" ), 36project_root : root. to_owned (), 37offline : true , 38frozen : false , 39update : false , 40ephemeral_lock : true , 41vendor : None , 42}, 43SourceAuthority :: execute ( caps. clone ()), 44) ?); 45let settings =Settings { 46snapshot : None , 47storage : avril_webstorage:: Persistent :: new ( 48 root. join ( "storage" ), 49& root. join ( "avril.conf" ), 50"snapshot" , 51), 52 caps, 53environment : Environment :: default (), 54args : Vec :: new (), 55store : store. clone (), 56runtime : host. handle (), 57broker : Arc :: default (), 58process_signal : SignalMode :: Run , 59}; 60let graph =Rc :: new ( ModuleGraph :: open_shared ( 61SourceAuthority :: execute ( settings. caps . clone ()), 62 store, 63)); 64let mut layouts =Vec :: new (); 65for workerin [ false , true ] { 66let scope =if worker{ 67Some ( WorkerScope { 68control : Arc :: default (), 69inbox : settings. broker . pair () ?. 1 , 70url : "https://worker.invalid/snapshot.js" . into (), 71name : String :: new (), 72}) 73} else { 74None 75}; 76let mut extensions =extensions ( 77 graph. clone (), 78 settings. clone (), 79Stdio :: new () ?, 80 scope, 81None , 82None , 83) ?; 84for extensionin & mut extensions{ 85for opin & mut extension. ops { 86// Only these operations depend solely on target and codec tables. 87if !matches! ( op. name , "op_path_platform" |"op_encoding_label" ) { 88let name = op. name ; 89* op =Op :: try_raw ( name, move |_, _|Err ( LiveOp ( name))); 90} 91} 92} 93 layouts. push ( RuntimeOptions { extensions, module_loader : None }); 94} 95Ok ( Runtime :: create_snapshot ( layouts) ?) 96}