@@ -23,13 +23,44 @@ pub struct AscCompileOptions {
2323 pub output_file : PathBuf ,
2424 /// Output format: "wasm" or "wast".
2525 pub output_format : String ,
26+ /// Skip the asc version check (use with caution).
27+ pub skip_version_check : bool ,
2628}
2729
30+ /// The required AssemblyScript compiler version.
31+ /// gnd functionality is very sensitive to asc version changes.
32+ const REQUIRED_ASC_VERSION : & str = "0.19.23" ;
33+
2834/// Compile an AssemblyScript mapping file to WebAssembly.
2935///
3036/// This shells out to the `asc` command-line tool with the appropriate flags
3137/// to match the graph-cli behavior.
38+ ///
39+ /// Requires asc version 0.19.23 to be installed.
3240pub fn compile_mapping ( options : & AscCompileOptions ) -> Result < ( ) > {
41+ // Check that asc is available
42+ if !is_asc_available ( ) {
43+ return Err ( anyhow ! (
44+ "AssemblyScript compiler (asc) not found. Please install it with:\n \
45+ npm install -g assemblyscript@{REQUIRED_ASC_VERSION}"
46+ ) ) ;
47+ }
48+
49+ // Check version unless explicitly skipped
50+ if !options. skip_version_check {
51+ let version = get_asc_version ( ) ?;
52+ if version != REQUIRED_ASC_VERSION {
53+ return Err ( anyhow ! (
54+ "AssemblyScript compiler version mismatch: found {}, required {}.\n \
55+ Please install the correct version with:\n \
56+ npm install -g assemblyscript@{REQUIRED_ASC_VERSION}\n \n \
57+ If you know what you're doing, use --skip-asc-version-check or set GND_SKIP_ASC_VERSION_CHECK=1 to bypass this check.",
58+ version,
59+ REQUIRED_ASC_VERSION
60+ ) ) ;
61+ }
62+ }
63+
3364 // Determine input and output paths relative to base_dir
3465 let input_rel = options
3566 . input_file
@@ -147,8 +178,7 @@ pub fn find_graph_ts(source_dir: &Path) -> Result<(Vec<PathBuf>, PathBuf)> {
147178}
148179
149180/// Check if the asc compiler is available.
150- #[ allow( dead_code) ]
151- pub fn is_asc_available ( ) -> bool {
181+ fn is_asc_available ( ) -> bool {
152182 Command :: new ( "asc" )
153183 . arg ( "--version" )
154184 . output ( )
@@ -157,8 +187,7 @@ pub fn is_asc_available() -> bool {
157187}
158188
159189/// Get the asc compiler version.
160- #[ allow( dead_code) ]
161- pub fn get_asc_version ( ) -> Result < String > {
190+ fn get_asc_version ( ) -> Result < String > {
162191 let output = Command :: new ( "asc" )
163192 . arg ( "--version" )
164193 . output ( )
@@ -168,7 +197,13 @@ pub fn get_asc_version() -> Result<String> {
168197 return Err ( anyhow ! ( "asc --version failed" ) ) ;
169198 }
170199
171- let version = String :: from_utf8_lossy ( & output. stdout ) . trim ( ) . to_string ( ) ;
200+ // Output is "Version X.Y.Z", extract just the version number
201+ let version_output = String :: from_utf8_lossy ( & output. stdout ) ;
202+ let version = version_output
203+ . trim ( )
204+ . strip_prefix ( "Version " )
205+ . unwrap_or ( version_output. trim ( ) )
206+ . to_string ( ) ;
172207 Ok ( version)
173208}
174209
@@ -207,9 +242,18 @@ mod tests {
207242 }
208243
209244 #[ test]
210- fn test_is_asc_available ( ) {
211- // This test just verifies the function doesn't panic
212- // The actual result depends on whether asc is installed
213- let _ = is_asc_available ( ) ;
245+ fn test_asc_version_check ( ) {
246+ // Skip if asc is not installed
247+ if !is_asc_available ( ) {
248+ return ;
249+ }
250+
251+ let version = get_asc_version ( ) . unwrap ( ) ;
252+ // Version should be a semver-like string (e.g., "0.19.23")
253+ assert ! (
254+ version. split( '.' ) . count( ) >= 2 ,
255+ "Version '{}' doesn't look like a semver" ,
256+ version
257+ ) ;
214258 }
215259}
0 commit comments