Skip to content

Commit fec0fdf

Browse files
Merge pull request #254 from bytecodealliance/revert-251-rust-fetch-wit-from-ghcr
Revert "Update rust guide and tutorial examples to use registries for WITs"
2 parents f06eb4f + bdfbd3d commit fec0fdf

File tree

6 files changed

+100
-117
lines changed

6 files changed

+100
-117
lines changed

component-model/examples/tutorial/adder/Cargo-component.lock

-12
This file was deleted.

component-model/examples/tutorial/adder/Cargo.toml

+6-12
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,11 @@ wit-bindgen-rt = { version = "0.37.0", features = ["bitflags"] }
99
[lib]
1010
crate-type = ["cdylib"]
1111

12-
# Tell cargo-component where to find the package for the target world
13-
# The following tells cargo-component to fetch the WIT from ghcr.io/bytecodealliance/docs/adder:0.1.0
14-
[package.metadata.component.target]
15-
# The registry which contains the package
16-
registry = "ghcr.io/bytecodealliance"
17-
# The package name
12+
[package.metadata.component]
1813
package = "docs:adder"
19-
# The package version
20-
version = "0.1.0"
2114

22-
# # To instead use a WIT on the local filesystem, uncomment the following lines
23-
# [package.metadata.component.target]
24-
# # Path to the directory containing the WIT
25-
# path = "../wit/adder"
15+
[package.metadata.component.dependencies]
16+
17+
[package.metadata.component.target]
18+
path = "../wit/adder"
19+
world = "adder"

component-model/examples/tutorial/adder/src/bindings.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ mod _rt {
122122
/// ```
123123
#[allow(unused_macros)]
124124
#[doc(hidden)]
125-
macro_rules! __export_root_impl {
125+
macro_rules! __export_adder_impl {
126126
($ty:ident) => {
127127
self::export!($ty with_types_in self);
128128
};
@@ -133,19 +133,19 @@ macro_rules! __export_root_impl {
133133
};
134134
}
135135
#[doc(inline)]
136-
pub(crate) use __export_root_impl as export;
136+
pub(crate) use __export_adder_impl as export;
137137
#[cfg(target_arch = "wasm32")]
138138
#[unsafe(
139-
link_section = "component-type:wit-bindgen:0.41.0:root:component:root:encoded world"
139+
link_section = "component-type:wit-bindgen:0.41.0:docs:adder@0.1.0:adder:encoded world"
140140
)]
141141
#[doc(hidden)]
142142
#[allow(clippy::octal_escapes)]
143-
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 199] = *b"\
144-
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07M\x01A\x02\x01A\x02\x01\
143+
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 203] = *b"\
144+
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07P\x01A\x02\x01A\x02\x01\
145145
B\x02\x01@\x02\x01xy\x01yy\0y\x04\0\x03add\x01\0\x04\0\x14docs:adder/add@0.1.0\x05\
146-
\0\x04\0\x13root:component/root\x04\0\x0b\x0a\x01\0\x04root\x03\0\0\0G\x09produc\
147-
ers\x01\x0cprocessed-by\x02\x0dwit-component\x070.227.1\x10wit-bindgen-rust\x060\
148-
.41.0";
146+
\0\x04\0\x16docs:adder/adder@0.1.0\x04\0\x0b\x0b\x01\0\x05adder\x03\0\0\0G\x09pr\
147+
oducers\x01\x0cprocessed-by\x02\x0dwit-component\x070.227.1\x10wit-bindgen-rust\x06\
148+
0.41.0";
149149
#[inline(never)]
150150
#[doc(hidden)]
151151
pub fn __link_custom_section_describing_imports() {

component-model/examples/tutorial/calculator/Cargo.toml

+7-14
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,14 @@ wit-bindgen-rt = { version = "0.24.0", features = ["bitflags"] }
99
[lib]
1010
crate-type = ["cdylib"]
1111

12-
# Tell cargo-component where to find the package for the target world
13-
# The following tells cargo-component to fetch the WIT from a local directory
12+
[package.metadata.component]
13+
package = "docs:calculator"
14+
15+
[package.metadata.component.target.dependencies]
16+
"docs:adder" = { path = "../wit/adder" } # directory containing the WIT package
17+
1418
[package.metadata.component.target]
15-
# Path to the directory containing the WIT
1619
path = "../wit/calculator"
17-
# World within the package to target
1820
world = "calculator"
1921

20-
[package.metadata.component.target.dependencies]
21-
# Tell cargo-component where to find the package for the dependencies
22-
"docs:adder" = { path = "../wit/adder" }
23-
24-
## To instead fetch the package and it's dependencies from a registry, uncomment the following lines
25-
# [package.metadata.component.target]
26-
# package = "docs:calculator"
27-
# version = "0.1.0"
28-
# registry = "ghcr.io/bytecodealliance"
29-
# world = "calculator"
22+
[package.metadata.component.dependencies]
Original file line numberDiff line numberDiff line change
@@ -1,177 +1,193 @@
1-
// Generated by `wit-bindgen` 0.41.0. DO NOT EDIT!
1+
// Generated by `wit-bindgen` 0.25.0. DO NOT EDIT!
22
// Options used:
3-
// * runtime_path: "wit_bindgen_rt"
4-
#[rustfmt::skip]
5-
#[allow(dead_code, clippy::all)]
3+
#[allow(dead_code)]
64
pub mod docs {
5+
#[allow(dead_code)]
76
pub mod adder {
8-
#[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)]
7+
#[allow(dead_code, clippy::all)]
98
pub mod add {
109
#[used]
1110
#[doc(hidden)]
12-
static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports;
11+
#[cfg(target_arch = "wasm32")]
12+
static __FORCE_SECTION_REF: fn() =
13+
super::super::super::__link_custom_section_describing_imports;
1314
use super::super::super::_rt;
1415
#[allow(unused_unsafe, clippy::all)]
1516
pub fn add(x: u32, y: u32) -> u32 {
1617
unsafe {
1718
#[cfg(target_arch = "wasm32")]
1819
#[link(wasm_import_module = "docs:adder/add@0.1.0")]
19-
unsafe extern "C" {
20+
extern "C" {
2021
#[link_name = "add"]
21-
fn wit_import0(_: i32, _: i32) -> i32;
22+
fn wit_import(_: i32, _: i32) -> i32;
2223
}
24+
2325
#[cfg(not(target_arch = "wasm32"))]
24-
unsafe extern "C" fn wit_import0(_: i32, _: i32) -> i32 {
26+
fn wit_import(_: i32, _: i32) -> i32 {
2527
unreachable!()
2628
}
27-
let ret = unsafe { wit_import0(_rt::as_i32(&x), _rt::as_i32(&y)) };
29+
let ret = wit_import(_rt::as_i32(&a), _rt::as_i32(&b));
2830
ret as u32
2931
}
3032
}
3133
}
3234
}
3335
}
34-
#[rustfmt::skip]
35-
#[allow(dead_code, clippy::all)]
36+
#[allow(dead_code)]
3637
pub mod exports {
38+
#[allow(dead_code)]
3739
pub mod docs {
40+
#[allow(dead_code)]
3841
pub mod calculator {
39-
#[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)]
42+
#[allow(dead_code, clippy::all)]
4043
pub mod calculate {
4144
#[used]
4245
#[doc(hidden)]
43-
static __FORCE_SECTION_REF: fn() = super::super::super::super::__link_custom_section_describing_imports;
46+
#[cfg(target_arch = "wasm32")]
47+
static __FORCE_SECTION_REF: fn() =
48+
super::super::super::super::__link_custom_section_describing_imports;
4449
use super::super::super::super::_rt;
4550
#[repr(u8)]
46-
#[derive(Clone, Copy, Eq, Ord, PartialEq, PartialOrd)]
51+
#[derive(Clone, Copy, Eq, PartialEq)]
4752
pub enum Op {
4853
Add,
4954
}
5055
impl ::core::fmt::Debug for Op {
51-
fn fmt(
52-
&self,
53-
f: &mut ::core::fmt::Formatter<'_>,
54-
) -> ::core::fmt::Result {
56+
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
5557
match self {
5658
Op::Add => f.debug_tuple("Op::Add").finish(),
5759
}
5860
}
5961
}
62+
6063
impl Op {
6164
#[doc(hidden)]
6265
pub unsafe fn _lift(val: u8) -> Op {
6366
if !cfg!(debug_assertions) {
6467
return ::core::mem::transmute(val);
6568
}
69+
6670
match val {
6771
0 => Op::Add,
72+
6873
_ => panic!("invalid enum discriminant"),
6974
}
7075
}
7176
}
77+
7278
#[doc(hidden)]
7379
#[allow(non_snake_case)]
7480
pub unsafe fn _export_eval_expression_cabi<T: Guest>(
7581
arg0: i32,
7682
arg1: i32,
7783
arg2: i32,
7884
) -> i32 {
79-
#[cfg(target_arch = "wasm32")] _rt::run_ctors_once();
80-
let result0 = T::eval_expression(
81-
Op::_lift(arg0 as u8),
82-
arg1 as u32,
83-
arg2 as u32,
84-
);
85+
#[cfg(target_arch = "wasm32")]
86+
_rt::run_ctors_once();
87+
let result0 =
88+
T::eval_expression(Op::_lift(arg0 as u8), arg1 as u32, arg2 as u32);
8589
_rt::as_i32(result0)
8690
}
8791
pub trait Guest {
8892
fn eval_expression(op: Op, x: u32, y: u32) -> u32;
8993
}
9094
#[doc(hidden)]
91-
macro_rules! __export_docs_calculator_calculate_0_1_0_cabi {
92-
($ty:ident with_types_in $($path_to_types:tt)*) => {
93-
const _ : () = { #[unsafe (export_name =
94-
"docs:calculator/calculate@0.1.0#eval-expression")] unsafe extern
95-
"C" fn export_eval_expression(arg0 : i32, arg1 : i32, arg2 :
96-
i32,) -> i32 { unsafe { $($path_to_types)*::
97-
_export_eval_expression_cabi::<$ty > (arg0, arg1, arg2) } } };
98-
};
99-
}
95+
96+
macro_rules! __export_docs_calculator_calculate_0_1_0_cabi{
97+
($ty:ident with_types_in $($path_to_types:tt)*) => (const _: () = {
98+
99+
#[export_name = "docs:calculator/calculate@0.1.0#eval-expression"]
100+
unsafe extern "C" fn export_eval_expression(arg0: i32,arg1: i32,arg2: i32,) -> i32 {
101+
$($path_to_types)*::_export_eval_expression_cabi::<$ty>(arg0, arg1, arg2)
102+
}
103+
};);
104+
}
100105
#[doc(hidden)]
101106
pub(crate) use __export_docs_calculator_calculate_0_1_0_cabi;
102107
}
103108
}
104109
}
105110
}
106-
#[rustfmt::skip]
107111
mod _rt {
108-
#![allow(dead_code, clippy::all)]
112+
109113
pub fn as_i32<T: AsI32>(t: T) -> i32 {
110114
t.as_i32()
111115
}
116+
112117
pub trait AsI32 {
113118
fn as_i32(self) -> i32;
114119
}
120+
115121
impl<'a, T: Copy + AsI32> AsI32 for &'a T {
116122
fn as_i32(self) -> i32 {
117123
(*self).as_i32()
118124
}
119125
}
126+
120127
impl AsI32 for i32 {
121128
#[inline]
122129
fn as_i32(self) -> i32 {
123130
self as i32
124131
}
125132
}
133+
126134
impl AsI32 for u32 {
127135
#[inline]
128136
fn as_i32(self) -> i32 {
129137
self as i32
130138
}
131139
}
140+
132141
impl AsI32 for i16 {
133142
#[inline]
134143
fn as_i32(self) -> i32 {
135144
self as i32
136145
}
137146
}
147+
138148
impl AsI32 for u16 {
139149
#[inline]
140150
fn as_i32(self) -> i32 {
141151
self as i32
142152
}
143153
}
154+
144155
impl AsI32 for i8 {
145156
#[inline]
146157
fn as_i32(self) -> i32 {
147158
self as i32
148159
}
149160
}
161+
150162
impl AsI32 for u8 {
151163
#[inline]
152164
fn as_i32(self) -> i32 {
153165
self as i32
154166
}
155167
}
168+
156169
impl AsI32 for char {
157170
#[inline]
158171
fn as_i32(self) -> i32 {
159172
self as i32
160173
}
161174
}
175+
162176
impl AsI32 for usize {
163177
#[inline]
164178
fn as_i32(self) -> i32 {
165179
self as i32
166180
}
167181
}
182+
168183
#[cfg(target_arch = "wasm32")]
169184
pub fn run_ctors_once() {
170185
wit_bindgen_rt::run_ctors_once();
171186
}
172187
}
173-
/// Generates `#[unsafe(no_mangle)]` functions to export the specified type as
174-
/// the root implementation of all generated traits.
188+
189+
/// Generates `#[no_mangle]` functions to export the specified type as the
190+
/// root implementation of all generated traits.
175191
///
176192
/// For more information see the documentation of `wit_bindgen::generate!`.
177193
///
@@ -188,34 +204,31 @@ mod _rt {
188204
/// ```
189205
#[allow(unused_macros)]
190206
#[doc(hidden)]
207+
191208
macro_rules! __export_calculator_impl {
192-
($ty:ident) => {
193-
self::export!($ty with_types_in self);
194-
};
195-
($ty:ident with_types_in $($path_to_types_root:tt)*) => {
196-
$($path_to_types_root)*::
197-
exports::docs::calculator::calculate::__export_docs_calculator_calculate_0_1_0_cabi!($ty
198-
with_types_in $($path_to_types_root)*:: exports::docs::calculator::calculate);
199-
};
209+
($ty:ident) => (self::export!($ty with_types_in self););
210+
($ty:ident with_types_in $($path_to_types_root:tt)*) => (
211+
$($path_to_types_root)*::exports::docs::calculator::calculate::__export_docs_calculator_calculate_0_1_0_cabi!($ty with_types_in $($path_to_types_root)*::exports::docs::calculator::calculate);
212+
)
200213
}
201214
#[doc(inline)]
202215
pub(crate) use __export_calculator_impl as export;
216+
203217
#[cfg(target_arch = "wasm32")]
204-
#[unsafe(
205-
link_section = "component-type:wit-bindgen:0.41.0:docs:calculator@0.1.0:calculator:encoded world"
206-
)]
218+
#[link_section = "component-type:wit-bindgen:0.25.0:calculator:encoded world"]
207219
#[doc(hidden)]
208-
#[allow(clippy::octal_escapes)]
209220
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 308] = *b"\
210221
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xb3\x01\x01A\x02\x01\
211-
A\x04\x01B\x02\x01@\x02\x01xy\x01yy\0y\x04\0\x03add\x01\0\x03\0\x14docs:adder/ad\
212-
d@0.1.0\x05\0\x01B\x04\x01m\x01\x03add\x04\0\x02op\x03\0\0\x01@\x03\x02op\x01\x01\
213-
xy\x01yy\0y\x04\0\x0feval-expression\x01\x02\x04\0\x1fdocs:calculator/calculate@\
214-
0.1.0\x05\x01\x04\0\x20docs:calculator/calculator@0.1.0\x04\0\x0b\x10\x01\0\x0ac\
215-
alculator\x03\0\0\0G\x09producers\x01\x0cprocessed-by\x02\x0dwit-component\x070.\
216-
227.1\x10wit-bindgen-rust\x060.41.0";
222+
A\x04\x01B\x02\x01@\x02\x01ay\x01by\0y\x04\0\x03add\x01\0\x03\x01\x14docs:adder/\
223+
add@0.1.0\x05\0\x01B\x04\x01m\x01\x03add\x04\0\x02op\x03\0\0\x01@\x03\x02op\x01\x01\
224+
xy\x01yy\0y\x04\0\x0feval-expression\x01\x02\x04\x01\x1fdocs:calculator/calculat\
225+
e@0.1.0\x05\x01\x04\x01\x20docs:calculator/calculator@0.1.0\x04\0\x0b\x10\x01\0\x0a\
226+
calculator\x03\0\0\0G\x09producers\x01\x0cprocessed-by\x02\x0dwit-component\x070\
227+
.208.1\x10wit-bindgen-rust\x060.25.0";
228+
217229
#[inline(never)]
218230
#[doc(hidden)]
231+
#[cfg(target_arch = "wasm32")]
219232
pub fn __link_custom_section_describing_imports() {
220233
wit_bindgen_rt::maybe_link_cabi_realloc();
221234
}

0 commit comments

Comments
 (0)