Skip to content

Commit 62cf499

Browse files
committed
Update Cargo.lock with new package 'hello-world' and 'wit-bindgen-rt'; modify justfile for component build and publish targets; adjust cd.yml for publishing process; refine discord Cargo.toml metadata.
1 parent 2e728da commit 62cf499

File tree

9 files changed

+179
-8
lines changed

9 files changed

+179
-8
lines changed

.github/workflows/cd.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ jobs:
5252
password: ${{ secrets.GITHUB_TOKEN }}
5353

5454
# Publish
55-
- run: wkg publish target/wasm32-wasip1/release/$(echo ${{ matrix.component }} | tr '-' '_').wasm --registry ghcr.io
55+
- run: cargo component publish -p ${{ matrix.component }} --target wasm32-unknown-unknown
5656

5757
# Make package public
5858
- run: |
5959
echo "Making package public..."
6060
curl -X PATCH \
6161
-H "Accept: application/vnd.github.v3+json" \
6262
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
63-
https://api.github.com/user/packages/container/${{ matrix.component }}/visibility \
63+
https://api.github.com/orgs/wassemble/packages/container/${{ matrix.component }}/visibility \
6464
-d '{"visibility":"public"}'

Cargo.lock

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

crates/discord/Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ crate-type = ["cdylib"]
1515
[package.metadata.component]
1616
package = "wassemble:discord"
1717

18-
[package.metadata.component.bindings]
19-
# derives = ["serde::Serialize", "serde::Deserialize"]
20-
21-
[package.metadata.component.dependencies]
18+
[package.metadata.component.target]
19+
path = "wit"
20+
world = "main"
2221

2322
[package.metadata.component.target.dependencies]
2423
"wasi:cli" = { path = "./wit/deps/wasi-cli-0.2.5" }

crates/hello-world/Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "hello-world"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
wit-bindgen-rt = { version = "0.42.1", features = ["bitflags"] }
8+
9+
[lib]
10+
crate-type = ["cdylib"]
11+
12+
[package.metadata.component]
13+
package = "wassemble:hello-world"
14+
15+
[package.metadata.component.target]
16+
path = "wit/world.wit"
17+
world = "main"

crates/hello-world/src/bindings.rs

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// Generated by `wit-bindgen` 0.41.0. DO NOT EDIT!
2+
// Options used:
3+
// * runtime_path: "wit_bindgen_rt"
4+
#[doc(hidden)]
5+
#[allow(non_snake_case)]
6+
pub unsafe fn _export_hello_world_cabi<T: Guest>() -> *mut u8 {
7+
#[cfg(target_arch = "wasm32")]
8+
_rt::run_ctors_once();
9+
let result0 = T::hello_world();
10+
let ptr1 = (&raw mut _RET_AREA.0).cast::<u8>();
11+
let vec2 = (result0.into_bytes()).into_boxed_slice();
12+
let ptr2 = vec2.as_ptr().cast::<u8>();
13+
let len2 = vec2.len();
14+
::core::mem::forget(vec2);
15+
*ptr1
16+
.add(::core::mem::size_of::<*const u8>())
17+
.cast::<usize>() = len2;
18+
*ptr1.add(0).cast::<*mut u8>() = ptr2.cast_mut();
19+
ptr1
20+
}
21+
#[doc(hidden)]
22+
#[allow(non_snake_case)]
23+
pub unsafe fn __post_return_hello_world<T: Guest>(arg0: *mut u8) {
24+
let l0 = *arg0.add(0).cast::<*mut u8>();
25+
let l1 = *arg0
26+
.add(::core::mem::size_of::<*const u8>())
27+
.cast::<usize>();
28+
_rt::cabi_dealloc(l0, l1, 1);
29+
}
30+
pub trait Guest {
31+
fn hello_world() -> _rt::String;
32+
}
33+
#[doc(hidden)]
34+
macro_rules! __export_world_main_cabi {
35+
($ty:ident with_types_in $($path_to_types:tt)*) => {
36+
const _ : () = { #[unsafe (export_name = "hello-world")] unsafe extern "C" fn
37+
export_hello_world() -> * mut u8 { unsafe { $($path_to_types)*::
38+
_export_hello_world_cabi::<$ty > () } } #[unsafe (export_name =
39+
"cabi_post_hello-world")] unsafe extern "C" fn _post_return_hello_world(arg0 : *
40+
mut u8,) { unsafe { $($path_to_types)*:: __post_return_hello_world::<$ty > (arg0)
41+
} } };
42+
};
43+
}
44+
#[doc(hidden)]
45+
pub(crate) use __export_world_main_cabi;
46+
#[cfg_attr(target_pointer_width = "64", repr(align(8)))]
47+
#[cfg_attr(target_pointer_width = "32", repr(align(4)))]
48+
struct _RetArea([::core::mem::MaybeUninit<u8>; 2 * ::core::mem::size_of::<*const u8>()]);
49+
static mut _RET_AREA: _RetArea =
50+
_RetArea([::core::mem::MaybeUninit::uninit(); 2 * ::core::mem::size_of::<*const u8>()]);
51+
#[rustfmt::skip]
52+
mod _rt {
53+
#![allow(dead_code, clippy::all)]
54+
#[cfg(target_arch = "wasm32")]
55+
pub fn run_ctors_once() {
56+
wit_bindgen_rt::run_ctors_once();
57+
}
58+
pub unsafe fn cabi_dealloc(ptr: *mut u8, size: usize, align: usize) {
59+
if size == 0 {
60+
return;
61+
}
62+
let layout = alloc::Layout::from_size_align_unchecked(size, align);
63+
alloc::dealloc(ptr, layout);
64+
}
65+
pub use alloc_crate::string::String;
66+
pub use alloc_crate::alloc;
67+
extern crate alloc as alloc_crate;
68+
}
69+
/// Generates `#[unsafe(no_mangle)]` functions to export the specified type as
70+
/// the root implementation of all generated traits.
71+
///
72+
/// For more information see the documentation of `wit_bindgen::generate!`.
73+
///
74+
/// ```rust
75+
/// # macro_rules! export{ ($($t:tt)*) => (); }
76+
/// # trait Guest {}
77+
/// struct MyType;
78+
///
79+
/// impl Guest for MyType {
80+
/// // ...
81+
/// }
82+
///
83+
/// export!(MyType);
84+
/// ```
85+
#[allow(unused_macros)]
86+
#[doc(hidden)]
87+
macro_rules! __export_main_impl {
88+
($ty:ident) => {
89+
self::export!($ty with_types_in self);
90+
};
91+
($ty:ident with_types_in $($path_to_types_root:tt)*) => {
92+
$($path_to_types_root)*:: __export_world_main_cabi!($ty with_types_in
93+
$($path_to_types_root)*);
94+
};
95+
}
96+
#[doc(inline)]
97+
pub(crate) use __export_main_impl as export;
98+
#[cfg(target_arch = "wasm32")]
99+
#[unsafe(link_section = "component-type:wit-bindgen:0.41.0:wassemble:hello-world:main:encoded world")]
100+
#[doc(hidden)]
101+
#[allow(clippy::octal_escapes)]
102+
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 180] = *b"\
103+
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07:\x01A\x02\x01A\x02\x01\
104+
@\0\0s\x04\0\x0bhello-world\x01\0\x04\0\x1awassemble:hello-world/main\x04\0\x0b\x0a\
105+
\x01\0\x04main\x03\0\0\0G\x09producers\x01\x0cprocessed-by\x02\x0dwit-component\x07\
106+
0.227.1\x10wit-bindgen-rust\x060.41.0";
107+
#[inline(never)]
108+
#[doc(hidden)]
109+
pub fn __link_custom_section_describing_imports() {
110+
wit_bindgen_rt::maybe_link_cabi_realloc();
111+
}

crates/hello-world/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#[allow(warnings)]
2+
mod bindings;
3+
4+
use bindings::Guest;
5+
6+
struct Component;
7+
8+
impl Guest for Component {
9+
/// Say hello!
10+
fn hello_world() -> String {
11+
"Hello, World!".to_string()
12+
}
13+
}
14+
15+
bindings::export!(Component with_types_in bindings);

crates/hello-world/wit/world.wit

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package wassemble:hello-world;
2+
3+
/// An example world for the component to target.
4+
world main {
5+
export hello-world: func() -> string;
6+
}

crates/hello-world/wkg.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# This file is automatically generated.
2+
# It is not intended for manual editing.
3+
version = 1
4+
packages = []

justfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ bindings component:
22
cd crates/{{component}} && wkg wit fetch && cargo component bindings
33

44
build component: (bindings component)
5-
cargo component build -p {{component}} --release
5+
cargo component build -p {{component}} --release --target wasm32-unknown-unknown
66

77
check:
88
cargo +nightly fmt
@@ -22,5 +22,8 @@ new component:
2222
cargo component new --editor none --lib --namespace wassemble crates/{{component}}
2323

2424
publish component: (build component)
25+
cargo component publish -p {{component}} --target wasm32-unknown-unknown
26+
27+
wit component: (build component)
2528
@safe_component=$(echo {{component}} | tr '-' '_') && \
26-
wkg oci push ghcr.io/wassemble/{{component}}:latest target/wasm32-wasip1/release/$safe_component.wasm
29+
wasm-tools component wit target/wasm32-unknown-unknown/release/$safe_component.wasm

0 commit comments

Comments
 (0)