1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
#![deny(missing_docs)]

//! A library shim around a mirror of the
//! official [webassembly MVP testsuite](https://github.com/WebAssembly/spec/tree/master/test/core).
//!
//! It can be used as a independent testsuite launcher for other
//! webassembly implementations by implementing `ScriptHandler`.
//!
//! Example:
//! ```should_fail
/*!
use greenwasm_spectest::*;

struct DummyHandler;
impl ScriptHandler for DummyHandler {
    fn reset(&mut self) {}
    fn action_invoke(&mut self,
                     module: Option<String>,
                     field: String,
                     args: Vec<Value>) -> InvokationResult
    {
        unimplemented!()
    }
    fn action_get(&mut self,
                  module: Option<String>,
                  field: String) -> Value
    {
        unimplemented!()
    }
    fn module(&mut self, bytes: Vec<u8>, name: Option<String>) {
        unimplemented!()
    }
    fn assert_malformed(&mut self, bytes: Vec<u8>) {
        unimplemented!()
    }
    fn assert_invalid(&mut self, bytes: Vec<u8>) {
        unimplemented!()
    }
    fn assert_uninstantiable(&mut self, bytes: Vec<u8>) {
        unimplemented!()
    }
    fn assert_exhaustion(&mut self, action: Action) {
        unimplemented!()
    }
    fn register(&mut self, name: Option<String>, as_name: String) {
        unimplemented!()
    }
}

run_mvp_spectest(&mut DummyHandler).present();
*/
//! ```
//! This would result in a output like this:
//! ```text
/*!
Executing address.wast ...
Executing align.wast ...
Executing binary.wast ...
Executing block.wast ...
Executing br.wast ...
[...]

wast failures:
    address.wast:3, not yet implemented
    address.wast:104, <not attempted>
    address.wast:105, <not attempted>
    ...
wast total: 0 passed; 17955 failed
*/
//! ```

pub extern crate wabt;
pub use wabt::script::Value;
pub use wabt::script::Action;
pub use wabt::script::CommandKind;

use std::path::Path;
use wabt::script::*;

/// Handles the different script commands of the `*.wast` format.
pub trait ScriptHandler {
    /// Reset all state of the handler, specifically
    /// clearing all loaded modules and assuming a new script file.
    fn reset(&mut self);

    /// Handles an `invoke` action.
    ///
    /// Should call a exported function with name `field` and arguments
    /// `args` from a loaded module.
    ///
    /// Targets either the last loaded module if `module` is None, or
    /// the module registered with the given name otherwise.
    fn action_invoke(&mut self, module: Option<String>, field: String, args: Vec<Value>) -> InvokationResult;

    /// Handles an `get` action.
    ///
    /// Should get a exported global with name `field` from a loaded module.
    ///
    /// Targets either the last loaded module if `module` is None, or
    /// the module registered with the given name otherwise.
    fn action_get(&mut self, module: Option<String>, field: String) -> Value;

    /// Handles an `action`.
    ///
    /// The default implementation dispatches to `action_get` or `
    /// action_invoke`, gathers the result in an vector, and panics
    /// if a function call trapped or exhausted the stack.
    fn action(&mut self, action: Action) -> Vec<Value> {
        match action {
            Action::Invoke { module, field, args } => {
                if let InvokationResult::Vals(v) = self.action_invoke(module, field, args) {
                    v
                } else {
                    panic!("invokation returned Trap or exhausted the stack");
                }
            }
            Action::Get { module, field } => {
                vec![self.action_get(module, field)]
            }
        }
    }

    /// Handles a module load.
    ///
    /// The webassembly module is passed in its binary format in
    /// the `bytes` argument.
    ///
    /// If `name` is `Some`, it should be registered under that name.
    /// In any case it should count as the least recently loaded module.
    fn module(&mut self, bytes: Vec<u8>, name: Option<String>);

    /// Handles an `assert_return`.
    ///
    /// Per default panics if the result of handling the `action`
    /// does not result in the `expected` values.
    ///
    /// Floating point values should, and per default are,
    /// compared according to their bit-pattern, and not their normal
    /// `PartialEq` semantic. See the `NanCompare` wrapper type.
    fn assert_return(&mut self, action: Action, expected: Vec<Value>) {
        let results = self.action(action);
        assert_eq!(NanCompare(&expected), NanCompare(&results));
    }

    /// Handles an `assert_trap`.
    ///
    /// Per default panics if the result of handling the `action`
    /// does not trap, or refers to an global.
    fn assert_trap(&mut self, action: Action) {
        match action {
            Action::Invoke { module, field, args } => {
                if let InvokationResult::Vals(results) = self.action_invoke(module, field, args) {
                    panic!("invokation did not trap, but returned {:?}", results);
                }
            }
            Action::Get { .. } => {
                panic!("a global access can not trap!")
            }
        }
    }

    /// Handles an `assert_malformed`.
    ///
    /// The webassembly module is passed in its binary format in
    /// the `bytes` argument.
    ///
    /// Should panic if the module can be successfully decoded.
    fn assert_malformed(&mut self, bytes: Vec<u8>);

    /// Handles an `assert_malformed`.
    ///
    /// The webassembly module is passed in its binary format in
    /// the `bytes` argument.
    ///
    /// Should panic if the module can be successfully decoded.
    fn assert_invalid(&mut self, bytes: Vec<u8>);

    /// Handles an `assert_unlinkable`.
    ///
    /// The webassembly module is passed in its binary format in
    /// the `bytes` argument.
    ///
    /// Should panic if the module can be successfully linked.
    ///
    /// This seems to be a legacy script command, and per default
    /// just invokes `assert_uninstantiable`.
    fn assert_unlinkable(&mut self, bytes: Vec<u8>) {
        // TODO: figure out the exact difference
        // Currently it looks like a link error is any instantiation error except
        // a runtime error during execution of a start function
        self.assert_uninstantiable(bytes);
    }

    /// Handles an `assert_uninstantiable`.
    ///
    /// The webassembly module is passed in its binary format in
    /// the `bytes` argument.
    ///
    /// Should panic if the module can be successfully instantiated.
    fn assert_uninstantiable(&mut self, bytes: Vec<u8>);

    /// Handles an `assert_trap`.
    ///
    /// Should panic if the result of handling the `action`
    /// does not exhaust the stack, or refers to an global.
    fn assert_exhaustion(&mut self, action: Action);

    /// Handles an `assert_return_canonical_nan`.
    ///
    /// Per default panics if the result of handling the `action`
    /// does not result in single canonical NaN floating point value.
    ///
    /// Any canonical NaN is also a arithmetic NaN.
    ///
    /// Floating point values should, and per default are,
    /// compared according to their bit-pattern, and not their normal
    /// `PartialEq` semantic. See the `NanCompare` wrapper type.
    fn assert_return_canonical_nan(&mut self, action: Action) {
        let results = self.action(action);
        match *results {
            [Value::F32(v)] if v.is_canonical_nan() => {}
            [Value::F64(v)] if v.is_canonical_nan() => {}
            ref x => {
                panic!("unexpected value {:?}", NanCompare(x));
            }
        }
    }

    /// Handles an `assert_return_arithmetic_nan`.
    ///
    /// Per default panics if the result of handling the `action`
    /// does not result in single arithmetic NaN floating point value.
    ///
    /// Any canonical NaN is also a arithmetic NaN.
    ///
    /// Floating point values should, and per default are,
    /// compared according to their bit-pattern, and not their normal
    /// `PartialEq` semantic. See the `NanCompare` wrapper type.
    fn assert_return_arithmetic_nan(&mut self, action: Action) {
        let results = self.action(action);
        match *results {
            [Value::F32(v)] if v.is_arithmetic_nan() => {}
            [Value::F64(v)] if v.is_arithmetic_nan() => {}
            ref x => {
                panic!("unexpected value {:?}", NanCompare(x));
            }
        }
    }

    /// Register a loaded module under the name `as_name`.
    ///
    /// If `name` is `Some`, it should be registered under that name.
    /// In any case it should count as the least recently loaded module.
    fn register(&mut self, name: Option<String>, as_name: String);
}

/// Wrapper type that compares a list of `wabt` `Value`s
/// according to their bit-pattern if they contain floating point values,
/// and according to regular `PartialEq` semantics otherwise.
pub struct NanCompare<'a>(pub &'a [Value]);

impl<'a> ::std::cmp::PartialEq for NanCompare<'a> {
    fn eq(&self, other: &Self) -> bool {
        if self.0.len() != other.0.len() {
            return false;
        }
        self.0.iter().zip(other.0.iter()).all(|pair| {
            match pair {
                (Value::I32(l), Value::I32(r)) => l == r,
                (Value::I64(l), Value::I64(r)) => l == r,
                (Value::F32(l), Value::F32(r)) if l.is_nan() && r.is_nan() => {
                    l.payload() == r.payload()
                },
                (Value::F64(l), Value::F64(r)) if l.is_nan() && r.is_nan() => {
                    l.payload() == r.payload()
                },
                (Value::F32(l), Value::F32(r)) => l == r,
                (Value::F64(l), Value::F64(r)) => l == r,
                _ => false,
            }
        })
    }
}
impl<'a> ::std::fmt::Debug for NanCompare<'a> {
    fn fmt(&self, formatter: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
        formatter.debug_list().entries(self.0.iter().map(|e| {
            match e {
                Value::F32(v) if v.is_nan() => {
                    let p = v.payload();
                    format!("F32(NaN:0x{:x})", p)
                }
                Value::F64(v) if v.is_nan() => {
                    let p = v.payload();
                    format!("F64(NaN:0x{:x})", p)
                }
                _ => format!("{:?}", e)
            }
        })).finish()
    }
}

/// Result of invoking a function.
pub enum InvokationResult {
    /// The function returned successfully with a number of `Value`s
    Vals(Vec<Value>),
    /// The function trapped.
    Trap,
    /// The function exhausted the stack.
    StackExhaustion,
}

/// Extension trait for floating point values.
///
/// Provides methods for accessing the payload
/// of a NaN according to the webassembly spec.
///
/// According to the spec, any canonical NaN is also an arithmetic one.
pub trait NanPayload {
    /// Returns the payload bits of a NaN value.
    fn payload(&self) -> u64;
    /// Returns the number of significant digits in a NaN value.
    fn signif() -> u32;
    /// Returns positive infinite.
    fn infinite() -> Self;
    /// Returns the payload of a canonical NaN.
    fn canonical_payload() -> u64;
    /// Returns an arithmetic NaN with the given payload.
    fn arithmetic_nan(payload: u64) -> Self;
    /// Returns a canonical NaN.
    fn canonical_nan() -> Self;
    /// Checks if a value is an arithmetic NaN.
    fn is_arithmetic_nan(&self) -> bool;
    /// Checks if a value is a canonical NaN.
    fn is_canonical_nan(&self) -> bool;
}
impl NanPayload for f32 {
    fn payload(&self) -> u64 {
        assert!(self.is_nan());
        let bits: u32 = self.to_bits();
        let mask: u32 = (1u32 << 23) - 1;
        let p = bits & mask;
        p as u64
    }
    fn signif() -> u32 { 23 }
    fn infinite() -> Self { 1.0 / 0.0 }
    fn canonical_payload() -> u64 {
        1u64 << (Self::signif() - 1)
    }
    fn arithmetic_nan(payload: u64) -> Self {
        assert!(payload >= Self::canonical_payload());
        let bits: u32 = Self::infinite().to_bits();
        let mask: u32 = (1u32 << Self::signif()) - 1;
        let bits = bits | (mask & (payload as u32));
        Self::from_bits(bits)
    }
    fn canonical_nan() -> Self {
        Self::arithmetic_nan(Self::canonical_payload())
    }
    fn is_arithmetic_nan(&self) -> bool {
        self.is_nan()
    }
    fn is_canonical_nan(&self) -> bool {
        self.is_nan() && self.abs().to_bits() == Self::canonical_nan().to_bits()
    }
}
impl NanPayload for f64 {
    fn payload(&self) -> u64 {
        assert!(self.is_nan());
        let bits: u64 = self.to_bits();
        let mask: u64 = (1u64 << 52) - 1;
        let p = bits & mask;
        p
    }
    fn signif() -> u32 { 52 }
    fn infinite() -> Self { 1.0 / 0.0 }
    fn canonical_payload() -> u64 {
        1u64 << (Self::signif() - 1)
    }
    fn arithmetic_nan(payload: u64) -> Self {
        assert!(payload >= Self::canonical_payload());
        let bits: u64 = Self::infinite().to_bits();
        let mask: u64 = (1u64 << Self::signif()) - 1;
        let bits = bits | (mask & payload);
        Self::from_bits(bits)
    }
    fn canonical_nan() -> Self {
        Self::arithmetic_nan(Self::canonical_payload())
    }
    fn is_arithmetic_nan(&self) -> bool {
        self.is_nan()
    }
    fn is_canonical_nan(&self) -> bool {
        self.is_nan() && self.abs().to_bits() == Self::canonical_nan().to_bits()
    }
}

/// Result of running a series of script commands.
#[must_use]
pub struct SpectestResult {
    /// List of failed commands consisting of
    /// (filename, line number, panic message) tuples.
    pub failures: Vec<(String, u64, String)>,

    /// Number of successful commands.
    pub successes: usize,
}

impl SpectestResult {
    /// Displays the results in `Self` in a form similar
    /// to Rusts testsuite, and raises an panic if any tests failed.
    ///
    /// This is intended to be called from a `#[test]` function.
    pub fn present(self) {
        if self.failures.len() > 0 {
            println!("wast failures:");
            for (i, f) in self.failures.iter().enumerate() {
                println!("    {}:{}, {}", f.0, f.1, f.2);
                if i > 10 {
                    println!("    ...");
                    break;
                }
            }
            println!("wast total: {} passed; {} failed", self.successes, self.failures.len());
            panic!("some wast commands failed");
        } else {
            println!("wast total: {} passed; {} failed", self.successes, self.failures.len());
        }
    }
}

/// Run all scripts of the bundled webassembly testsuite on `handler`.
pub fn run_mvp_spectest<T: ScriptHandler>(handler: &mut T) -> SpectestResult {
    run_all_in_directory(format!("{}/testsuite", env!("CARGO_MANIFEST_DIR")).as_ref(), handler)
}

/// Module that is expected under the name "spectest" by all spectest testcases.
///
/// This is automatically registered by all `run_` functions in this modules
/// that work at file granularity or higher.
pub const SPECTEST_MODULE: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/spectest.wasm"));

/// Run all scripts in a given directory on `handler`.
pub fn run_all_in_directory<T: ScriptHandler>(path: &Path, handler: &mut T) -> SpectestResult {
    use std::fs;
    let mut res = SpectestResult {
        failures: vec![],
        successes: 0,
    };

    println!("\n\nRunning testsuite at {}:\n", path.display());

    'outer: for dir in fs::read_dir(&path).unwrap() {
        let dir = dir.unwrap();
        let path = dir.path();
        let filename = path.file_name().unwrap().to_str().unwrap();

        if path.metadata().unwrap().file_type().is_file() && filename.ends_with(".wast") {
            println!("Executing {} ...", filename);
            let res2 = run_single_file(&path, handler);
            res.successes += res2.successes;
            res.failures.extend(res2.failures);
        }
    }

    return res;
}

/// Run `handler` on the single `.wast` script file at `path`.
pub fn run_single_file<T: ScriptHandler>(path: &Path, handler: &mut T) -> SpectestResult {
    use std::fs;

    let mut res = SpectestResult {
        failures: vec![],
        successes: 0,
    };

    let filename = path.file_name().unwrap().to_str().unwrap();
    let source = fs::read(&path).unwrap();

    let mut script = ScriptParser::<>::from_source_and_name(&source, filename).unwrap();
    let mut fatal = false;

    handler.reset();
    {
        let module = SPECTEST_MODULE.to_vec();
        let name = Some("spectest".into());

        use std::panic::*;

        let r = if let Err(msg) = catch_unwind(AssertUnwindSafe(|| {
            handler.module(module, name);
        })) {
            let msg = if let Some(msg) = msg.downcast_ref::<String>() {
                msg.to_string()
            } else if let Some(msg) = msg.downcast_ref::<&'static str>() {
                msg.to_string()
            } else {
                "<unknown>".to_string()
            };
            Err(msg)
        } else {
            Ok(())
        };

        match r {
            Err(msg) => {
                res.failures.push(("<internal spectest module>".to_owned(), 0, msg));
                fatal = true;
            }
            Ok(()) => {
                res.successes += 1;
            }
        }
    }

    while let Some(Command { line, kind }) = script.next().unwrap() {
        if fatal {
            res.failures.push((filename.to_owned(), line, "<not attempted>".to_string()));
            continue;
        }
        match run_single_command(kind, handler) {
            Err(msg) => {
                res.failures.push((filename.to_owned(), line, msg));
                fatal = true;
            }
            Ok(()) => {
                res.successes += 1;
            }
        }
    }

    return res;
}

/// Run `handler` on a single wabt script command, catching any panic that
/// might happen in the process.
///
/// Note that `T` needs to be exception safe, in the sense that any
/// panic that happened during a method call should not affect it beyond
/// a subsequent `reset()` call.
pub fn run_single_command<T: ScriptHandler>(kind: CommandKind, handler: &mut T) -> Result<(), String> {
    use std::panic::*;

    if let Err(msg) = catch_unwind(AssertUnwindSafe(|| {
        run_single_command_no_catch(kind, handler);
    })) {
        let msg = if let Some(msg) = msg.downcast_ref::<String>() {
            msg.to_string()
        } else if let Some(msg) = msg.downcast_ref::<&'static str>() {
            msg.to_string()
        } else {
            "<unknown>".to_string()
        };
        Err(msg)
    } else {
        Ok(())
    }
}

/// Run `handler` on a single wabt script command.
///
/// Unlike `run_single_command`, this does not catch a panic.
pub fn run_single_command_no_catch<C: ScriptHandler>(cmd: CommandKind, c: &mut C) {
    // TODO: Figure out if the "message" fields need to actually be handled
    use wabt::script::CommandKind::*;
    match cmd {
        Module { module, name } => {
            c.module(module.into_vec(), name);
        }
        AssertReturn { action, expected } => {
            c.assert_return(action, expected);
        }
        AssertReturnCanonicalNan { action } => {
            c.assert_return_canonical_nan(action);
        }
        AssertReturnArithmeticNan { action } => {
            c.assert_return_arithmetic_nan(action);
        }
        AssertTrap { action, message: _ } => {
            c.assert_trap(action);
        }
        AssertInvalid { module, message: _ } => {
            c.assert_invalid(module.into_vec());
        }
        AssertMalformed { module, message: _ } => {
            c.assert_malformed(module.into_vec());
        }
        AssertUninstantiable { module, message: _ } => {
            c.assert_uninstantiable(module.into_vec());
        }
        AssertExhaustion { action } => {
            c.assert_exhaustion(action);
        }
        AssertUnlinkable { module, message: _ } => {
            c.assert_unlinkable(module.into_vec());
        }
        Register { name, as_name } => {
            c.register(name, as_name);
        }
        PerformAction(action) => {
            c.action(action);
        }
    }
}

/*
Spectest module .wat, based on wabt's spectest-interp.cc

static void InitEnvironment(Environment* env) {
  HostModule* host_module = env->AppendHostModule("spectest");
  host_module->AppendFuncExport("print", {{}, {}}, PrintCallback);
  host_module->AppendFuncExport("print_i32", {{Type::I32}, {}}, PrintCallback);
  host_module->AppendFuncExport("print_f32", {{Type::F32}, {}}, PrintCallback);
  host_module->AppendFuncExport("print_f64", {{Type::F64}, {}}, PrintCallback);
  host_module->AppendFuncExport("print_i32_f32", {{Type::I32, Type::F32}, {}},
                                PrintCallback);
  host_module->AppendFuncExport("print_f64_f64", {{Type::F64, Type::F64}, {}},
                                PrintCallback);

  host_module->AppendTableExport("table", Limits(10, 20));
  host_module->AppendMemoryExport("memory", Limits(1, 2));

  host_module->AppendGlobalExport("global_i32", false, uint32_t(666));
  host_module->AppendGlobalExport("global_i64", false, uint64_t(666));
  host_module->AppendGlobalExport("global_f32", false, float(666.6f));
  host_module->AppendGlobalExport("global_f64", false, double(666.6));
}

=>

(module
  (type (func))
  (type (func (param i32)))
  (type (func (param f32)))
  (type (func (param f64)))
  (type (func (param i32) (param f32)))
  (type (func (param f64) (param f64)))
  (func (type 0))
  (func (type 1))
  (func (type 2))
  (func (type 3))
  (func (type 4))
  (func (type 5))
  (table 10 20 anyfunc)
  (memory 1 2)
  (global i32 (i32.const 666))
  (global i64 (i64.const 666))
  (global f32 (f32.const 666.6))
  (global f64 (f64.const 666.6))
  (export "print" (func 0))
  (export "print_i32" (func 1))
  (export "print_f32" (func 2))
  (export "print_f64" (func 3))
  (export "print_i32_f32" (func 4))
  (export "print_f64_f64" (func 5))
  (export "table" (table 0))
  (export "memory" (memory 0))
  (export "global_i32" (global 0))
  (export "global_i64" (global 1))
  (export "global_f32" (global 2))
  (export "global_f64" (global 3))
)


the file spectest.wasm in the crate root contains a copy of it as a binary module
*/