Skip to content

Commit 639f58e

Browse files
committed
feat: Update to Wasmer 2.0.
The only breaking change is the renaming of the engines: JIT becomes Universal, and Native becomes Dylib. To avoid this breaking change, JIT extends Universal and Native extends Dylib, and they become deprecated. Test cases have been added to ensure the same behavior with JIT and Native.
1 parent 02fa43d commit 639f58e

36 files changed

+657
-548
lines changed

Cargo.lock

Lines changed: 328 additions & 300 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api/engine/index.html

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ <h1 class="title">Module <code>engine</code></h1>
3232
</ol>
3333
<p>It currently has two implementations:</p>
3434
<ol>
35-
<li>JIT with <code><a title="engine.JIT" href="#engine.JIT">JIT</a></code>,</li>
36-
<li>Native with <code><a title="engine.Native" href="#engine.Native">Native</a></code>.</li>
35+
<li>Universal with <code><a title="engine.Universal" href="#engine.Universal">Universal</a></code>,</li>
36+
<li>Dylib with <code><a title="engine.Dylib" href="#engine.Dylib">Dylib</a></code>.</li>
3737
</ol>
3838
<p>Both engines receive an optional compiler. If absent, engines will
3939
run in headless mode, i.e. they won't be able to compile (create)
@@ -42,20 +42,20 @@ <h1 class="title">Module <code>engine</code></h1>
4242
<ul>
4343
<li><code><a title="wasmer_compiler_cranelift" href="../wasmer_compiler_cranelift/index.html">wasmer_compiler_cranelift</a></code> to use the Cranelift compiler,</li>
4444
<li><code><a title="wasmer_compiler_llvm" href="../wasmer_compiler_llvm/index.html">wasmer_compiler_llvm</a></code> to use the LLVM compiler,</li>
45-
<li><code><a title="wasmer_compiler_singlepass" href="../wasmer_compiler_singlepass/index.html">wasmer_compiler_singlepass</a></code> to use the Singlepass compiler.</li>
45+
<li><code>wasmer_compiler_singlepass</code> to use the Singlepass compiler.</li>
4646
</ul>
4747
<h2 id="example">Example</h2>
48-
<p>Create a JIT engine with no compiler (headless mode):</p>
48+
<p>Create a Universal engine with no compiler (headless mode):</p>
4949
<pre><code class="language-py">from wasmer import engine
5050

51-
engine = engine.JIT()
52-
</code></pre>
53-
<p>Create a JIT engine with the LLVM compiler:</p>
54-
<pre><code class="language-py">from wasmer import engine
55-
from wasmer_compiler_llvm import Compiler
56-
57-
engine = engine.JIT(Compiler)
51+
engine = engine.Universal()
5852
</code></pre>
53+
<p>Create a Universal engine with the LLVM compiler:</p>
54+
<p>```py,ignore
55+
from wasmer import engine
56+
from wasmer_compiler_llvm import Compiler</p>
57+
<p>engine = engine.Universal(Compiler)
58+
```</p>
5959
<p>Engines are stored inside the <code><a title="wasmer.Store" href="../wasmer/index.html#wasmer.Store">Store</a></code>.</p>
6060
</section>
6161
<section>
@@ -67,31 +67,63 @@ <h2 id="example">Example</h2>
6767
<section>
6868
<h2 class="section-title" id="header-classes">Classes</h2>
6969
<dl>
70-
<dt id="engine.JIT"><code class="flex name class">
71-
<span>class <span class="ident">JIT</span></span>
70+
<dt id="engine.Dylib"><code class="flex name class">
71+
<span>class <span class="ident">Dylib</span></span>
7272
<span>(</span><span>compiler, target, /)</span>
7373
</code></dt>
7474
<dd>
75-
<div class="desc"><p>JIT engine for Wasmer compilers.</p>
76-
<p>Given an optional compiler, it generates the compiled machine code,
75+
<div class="desc"><p>Dylib engine for Wasmer compilers.</p>
76+
<p>Given an optional compiler, it generates a shared object file
77+
(<code>.so</code>, <code>.dylib</code> or <code>.dll</code> depending on the target), saves it
78+
temporarily to disk and uses it dylibly via <code>dlopen</code> and <code>dlsym</code>.
7779
and publishes it into memory so it can be used externally.</p>
7880
<p>If the compiler is absent, it will generate a headless engine.</p>
7981
<p>It is possible to specify a <code>Target</code> to possibly cross-compile for
8082
a different target. It requires a compiler.</p></div>
83+
<h3>Subclasses</h3>
84+
<ul class="hlist">
85+
<li>builtins.Native</li>
86+
</ul>
87+
</dd>
88+
<dt id="engine.JIT"><code class="flex name class">
89+
<span>class <span class="ident">JIT</span></span>
90+
<span>(</span><span>compiler, target, /)</span>
91+
</code></dt>
92+
<dd>
93+
<div class="desc"><p>Deprecated engine. Please use the parent engine instead,
94+
i.e. <code><a title="engine.Universal" href="#engine.Universal">Universal</a></code>.</p></div>
95+
<h3>Ancestors</h3>
96+
<ul class="hlist">
97+
<li>builtins.Universal</li>
98+
</ul>
8199
</dd>
82100
<dt id="engine.Native"><code class="flex name class">
83101
<span>class <span class="ident">Native</span></span>
84102
<span>(</span><span>compiler, target, /)</span>
85103
</code></dt>
86104
<dd>
87-
<div class="desc"><p>Native engine for Wasmer compilers.</p>
88-
<p>Given an optional compiler, it generates a shared object file
89-
(<code>.so</code>, <code>.dylib</code> or <code>.dll</code> depending on the target), saves it
90-
temporarily to disk and uses it natively via <code>dlopen</code> and <code>dlsym</code>.
105+
<div class="desc"><p>Deprecated engine. Please use the parent engine instead,
106+
i.e. <code><a title="engine.Dylib" href="#engine.Dylib">Dylib</a></code>.</p></div>
107+
<h3>Ancestors</h3>
108+
<ul class="hlist">
109+
<li>builtins.Dylib</li>
110+
</ul>
111+
</dd>
112+
<dt id="engine.Universal"><code class="flex name class">
113+
<span>class <span class="ident">Universal</span></span>
114+
<span>(</span><span>compiler, target, /)</span>
115+
</code></dt>
116+
<dd>
117+
<div class="desc"><p>Universal engine for Wasmer compilers.</p>
118+
<p>Given an optional compiler, it generates the compiled machine code,
91119
and publishes it into memory so it can be used externally.</p>
92120
<p>If the compiler is absent, it will generate a headless engine.</p>
93121
<p>It is possible to specify a <code>Target</code> to possibly cross-compile for
94122
a different target. It requires a compiler.</p></div>
123+
<h3>Subclasses</h3>
124+
<ul class="hlist">
125+
<li>builtins.JIT</li>
126+
</ul>
95127
</dd>
96128
</dl>
97129
</section>
@@ -112,11 +144,17 @@ <h1>Index</h1>
112144
<li><h3><a href="#header-classes">Classes</a></h3>
113145
<ul>
114146
<li>
147+
<h4><code><a title="engine.Dylib" href="#engine.Dylib">Dylib</a></code></h4>
148+
</li>
149+
<li>
115150
<h4><code><a title="engine.JIT" href="#engine.JIT">JIT</a></code></h4>
116151
</li>
117152
<li>
118153
<h4><code><a title="engine.Native" href="#engine.Native">Native</a></code></h4>
119154
</li>
155+
<li>
156+
<h4><code><a title="engine.Universal" href="#engine.Universal">Universal</a></code></h4>
157+
</li>
120158
</ul>
121159
</li>
122160
</ul>

docs/api/target/index.html

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -32,43 +32,37 @@ <h1 class="title">Module <code>target</code></h1>
3232
target for the compiler. A <code><a title="target.Target" href="#target.Target">Target</a></code> is defined by a <code><a title="target.Triple" href="#target.Triple">Triple</a></code> and
3333
<code><a title="target.CpuFeatures" href="#target.CpuFeatures">CpuFeatures</a></code> (optional).</p>
3434
<h2 id="example">Example</h2>
35-
<pre><code class="language-py">from wasmer import engine, target, Store, Module
36-
from wasmer_compiler_cranelift import Compiler
37-
38-
# Build a triple from a string.
39-
triple = target.Triple('x86_64-linux-musl')
40-
41-
# Build the CPU features (optional).
42-
cpu_features = target.CpuFeatures()
43-
cpu_features.add('sse2')
44-
45-
# Build the target.
46-
target = target.Target(triple, cpu_features)
47-
48-
# There we go. When creating the engine, pass the compiler _and_
49-
# the target.
50-
engine = engine.Native(Compiler, target)
51-
52-
# And finally, build the store with the engine.
53-
store = Store(engine)
54-
55-
# Now, let's compile the module for the defined target.
56-
module = Module(
57-
store,
58-
&quot;&quot;&quot;
59-
(module
60-
(type $sum_t (func (param i32 i32) (result i32)))
61-
(func $sum_f (type $sum_t) (param $x i32) (param $y i32) (result i32)
62-
local.get $x
63-
local.get $y
64-
i32.add)
65-
(export &quot;sum&quot; (func $sum_f)))
66-
&quot;&quot;&quot;
67-
)
68-
69-
# What's next? Serialize the module, and execute it on the
70-
# targeted host.
71-
</code></pre>
35+
<p>```py,ignore
36+
from wasmer import engine, target, Store, Module
37+
from wasmer_compiler_cranelift import Compiler</p>
38+
<h1 id="build-a-triple-from-a-string">Build a triple from a string.</h1>
39+
<p>triple = target.Triple('x86_64-linux-musl')</p>
40+
<h1 id="build-the-cpu-features-optional">Build the CPU features (optional).</h1>
41+
<p>cpu_features = target.CpuFeatures()
42+
cpu_features.add('sse2')</p>
43+
<h1 id="build-the-target">Build the target.</h1>
44+
<p>target = target.Target(triple, cpu_features)</p>
45+
<h1 id="there-we-go-when-creating-the-engine-pass-the-compiler-and">There we go. When creating the engine, pass the compiler <em>and</em></h1>
46+
<h1 id="the-target">the target.</h1>
47+
<p>engine = engine.Dylib(Compiler, target)</p>
48+
<h1 id="and-finally-build-the-store-with-the-engine">And finally, build the store with the engine.</h1>
49+
<p>store = Store(engine)</p>
50+
<h1 id="now-lets-compile-the-module-for-the-defined-target">Now, let's compile the module for the defined target.</h1>
51+
<p>module = Module(
52+
store,
53+
"""
54+
(module
55+
(type $sum_t (func (param i32 i32) (result i32)))
56+
(func $sum_f (type $sum_t) (param $x i32) (param $y i32) (result i32)
57+
local.get $x
58+
local.get $y
59+
i32.add)
60+
(export "sum" (func $sum_f)))
61+
"""
62+
)</p>
63+
<h1 id="whats-next-serialize-the-module-and-execute-it-on-the">What's next? Serialize the module, and execute it on the</h1>
64+
<h1 id="targeted-host">targeted host.</h1>
65+
<p>```</p>
7266
</section>
7367
<section>
7468
</section>
@@ -251,6 +245,15 @@ <h1>Index</h1>
251245
<div class="toc">
252246
<ul>
253247
<li><a href="#example">Example</a></li>
248+
<li><a href="#build-a-triple-from-a-string">Build a triple from a string.</a></li>
249+
<li><a href="#build-the-cpu-features-optional">Build the CPU features (optional).</a></li>
250+
<li><a href="#build-the-target">Build the target.</a></li>
251+
<li><a href="#there-we-go-when-creating-the-engine-pass-the-compiler-and">There we go. When creating the engine, pass the compiler and</a></li>
252+
<li><a href="#the-target">the target.</a></li>
253+
<li><a href="#and-finally-build-the-store-with-the-engine">And finally, build the store with the engine.</a></li>
254+
<li><a href="#now-lets-compile-the-module-for-the-defined-target">Now, let's compile the module for the defined target.</a></li>
255+
<li><a href="#whats-next-serialize-the-module-and-execute-it-on-the">What's next? Serialize the module, and execute it on the</a></li>
256+
<li><a href="#targeted-host">targeted host.</a></li>
254257
</ul>
255258
</div>
256259
<ul id="index">

docs/api/wasi/index.html

Lines changed: 9 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ <h2 id="example">Example</h2>
4949
# Now we are ready to instantiate the module.
5050
instance = Instance(module, import_object)
5151

52-
# … But (!) WASI needs an access to the memory of the
53-
# module. Simple, pass it.
54-
wasi_env.memory = instance.exports.memory
55-
5652
# Here we go, let's start the program.
5753
instance.exports._start()
5854
</code></pre>
@@ -82,44 +78,12 @@ <h2 class="section-title" id="header-classes">Classes</h2>
8278
<dl>
8379
<dt id="wasi.Environment"><code class="flex name class">
8480
<span>class <span class="ident">Environment</span></span>
81+
<span>(</span><span>...)</span>
8582
</code></dt>
8683
<dd>
8784
<div class="desc"><p>The environment provided to the WASI imports.</p>
8885
<p>To build it, use <code><a title="wasi.StateBuilder" href="#wasi.StateBuilder">StateBuilder</a></code>. See <code><a title="wasi.StateBuilder.finalize" href="#wasi.StateBuilder.finalize">StateBuilder.finalize()</a></code> to
8986
learn more.</p></div>
90-
<h3>Instance variables</h3>
91-
<dl>
92-
<dt id="wasi.Environment.memory"><code class="name">var <span class="ident">memory</span></code></dt>
93-
<dd>
94-
<div class="desc"><p>Set a memory to the WASI. Usually, it is a <code><a title="wasmer.Memory" href="../wasmer/index.html#wasmer.Memory">Memory</a></code>
95-
object from <code>instance.exports.&lt;memory_name&gt;</code>.</p>
96-
<h2 id="example">Example</h2>
97-
<pre><code class="language-py">from wasmer import wasi, Store, Module, Instance
98-
99-
store = Store()
100-
module = Module(store, open('tests/wasi.wasm', 'rb').read())
101-
102-
# Get the WASI version.
103-
wasi_version = wasi.get_version(module, strict=True)
104-
105-
# Build a WASI environment for the imports.
106-
wasi_env = wasi.StateBuilder('test-program').argument('--foo').finalize()
107-
108-
# Generate an `ImportObject` from the WASI environment.
109-
import_object = wasi_env.generate_import_object(store, wasi_version)
110-
111-
# Now we are ready to instantiate the module.
112-
instance = Instance(module, import_object)
113-
114-
# … But (!) WASI needs an access to the memory of the
115-
# module. Simple, pass it.
116-
wasi_env.memory = instance.exports.memory
117-
118-
# Here we go, let's start the program.
119-
instance.exports._start()
120-
</code></pre></div>
121-
</dd>
122-
</dl>
12387
<h3>Methods</h3>
12488
<dl>
12589
<dt id="wasi.Environment.generate_import_object"><code class="name flex">
@@ -135,7 +99,7 @@ <h2 id="example">Example</h2>
13599
<pre><code class="language-py">from wasmer import wasi, Store
136100

137101
store = Store()
138-
wasi_env = wasi.StateBuilder('test-program').argument('--foo')
102+
wasi_env = wasi.StateBuilder('test-program').argument('--foo').finalize()
139103
import_object = wasi_env.generate_import_object(store, wasi.Version.SNAPSHOT1)
140104
</code></pre></div>
141105
</dd>
@@ -277,7 +241,7 @@ <h2 id="example">Example</h2>
277241

278242
wasi_state_builder = \
279243
wasi.StateBuilder('test-program'). \
280-
preopen_directories([&quot;foo&quot;, &quot;bar&quot;])
244+
preopen_directories([&quot;.&quot;])
281245
</code></pre></div>
282246
</dd>
283247
<dt id="wasi.StateBuilder.preopen_directory"><code class="name flex">
@@ -290,13 +254,12 @@ <h2 id="example">Example</h2>
290254
directory.</p>
291255
<p>This method returns <code>self</code>.</p>
292256
<h2 id="example">Example</h2>
293-
<pre><code class="language-py">from wasmer import wasi
294-
295-
wasi_state_builder = \
296-
wasi.StateBuilder('test-program'). \
297-
preopen_directory(&quot;foo&quot;). \
298-
preopen_directory(&quot;bar&quot;)
299-
</code></pre></div>
257+
<p>```py,ignore
258+
from wasmer import wasi</p>
259+
<p>wasi_state_builder = \
260+
wasi.StateBuilder('test-program'). \
261+
preopen_directory(".")
262+
```</p></div>
300263
</dd>
301264
</dl>
302265
</dd>
@@ -355,7 +318,6 @@ <h1>Index</h1>
355318
<h4><code><a title="wasi.Environment" href="#wasi.Environment">Environment</a></code></h4>
356319
<ul class="">
357320
<li><code><a title="wasi.Environment.generate_import_object" href="#wasi.Environment.generate_import_object">generate_import_object</a></code></li>
358-
<li><code><a title="wasi.Environment.memory" href="#wasi.Environment.memory">memory</a></code></li>
359321
</ul>
360322
</li>
361323
<li>

0 commit comments

Comments
 (0)