Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add webidl example #544

Merged

Conversation

vados-cosmonic
Copy link
Collaborator

No description provided.

@vados-cosmonic vados-cosmonic changed the title Examples=add webidl example chore: add webidl example Jan 17, 2025
Copy link
Collaborator

@guybedford guybedford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great start! Will be so useful to have this.

I think npm install is not enough here due to the Rust step in getting webidl2wit running. Would be great to see the steps fleshed out on that.

Then to have a test JS file that can show how the imports get picked up and describing the two Jco conventions used for the WIT conversion per https://bytecodealliance.github.io/jco/transpiling.html#experimental-webidl-imports.

@vados-cosmonic
Copy link
Collaborator Author

I think npm install is not enough here due to the Rust step in getting webidl2wit running. Would be great to see the steps fleshed out on that.

Ah yes -- so there actually wasn't a webidl2wit that was installable :) Been spending some time in https://github.com/wasi-gfx/webidl2wit getting a usable CLI put together.

Then to have a test JS file that can show how the imports get picked up and describing the two Jco conventions used for the WIT conversion per https://bytecodealliance.github.io/jco/transpiling.html#experimental-webidl-imports.

Yup -- will do! book-library.js will turn into this, thanks for pointing out the docs to link to

@vados-cosmonic vados-cosmonic force-pushed the examples=add-webidl-example branch from 7c57d93 to 3242131 Compare February 5, 2025 15:37
@guybedford
Copy link
Collaborator

guybedford commented Feb 26, 2025

This would be great to land - can we get the example running on CI?

@vados-cosmonic vados-cosmonic marked this pull request as ready for review March 4, 2025 20:43
@vados-cosmonic
Copy link
Collaborator Author

Hey @guybedford so I got this working -- it requires a few things though:

  • webidl2wit needs to merge a PR upstream (I can merge it there and release but would love for Mendy to get a chance to take a look first)
  • jco needed a fix -- Classes didn't seem to work properly when passed through the globalThis and proxied

I'm going to make a separate PR for the jco fix so it can be reviewed by itself, but wanted to note it here (it all works in this PR)

@vados-cosmonic
Copy link
Collaborator Author

Hey @guybedford this PR is now only blocked on merge + release of #584 (webidl2wit fixes were doable on this side!), since examples use the published jco toolchain

@vados-cosmonic vados-cosmonic force-pushed the examples=add-webidl-example branch from a935366 to f8bb74c Compare March 6, 2025 23:54
@guybedford
Copy link
Collaborator

With this working, were we going to add it to CI like the others?

@vados-cosmonic vados-cosmonic force-pushed the examples=add-webidl-example branch from 5098ed3 to 9287851 Compare March 7, 2025 03:35
@vados-cosmonic
Copy link
Collaborator Author

Yeah so we can't actually test demo.js until a new jco version is released with #584 -- I was going to do that as a follow up post-release.

What I can do though is make sure the compilation works, so I've added that.

@vados-cosmonic vados-cosmonic force-pushed the examples=add-webidl-example branch from 9287851 to fdc6349 Compare March 7, 2025 12:34
@guybedford
Copy link
Collaborator

@vados-cosmonic we should be able to run all the examples against the latest Jco in the main workspace itself which should then link in the local preview2-shims from the workspace as well.

I think all you need to do is set the @bytecodealliance/jco package dependency to file:../../ in the examples packages.

@vados-cosmonic
Copy link
Collaborator Author

vados-cosmonic commented Mar 10, 2025

Ah good idea -- will use a relative dep in the WebIDL example!

[EDIT] - Done!

@vados-cosmonic vados-cosmonic force-pushed the examples=add-webidl-example branch from 22cdc96 to 3515f37 Compare March 10, 2025 17:35
@guybedford
Copy link
Collaborator

Alternatively try adding the examples folders to the workspace itself.

@guybedford
Copy link
Collaborator

Perhaps something like:

  "workspaces": [
    ".",
    "packages/preview2-shim",
    "examples/components/webidl-book-library"
  ]

in https://github.com/bytecodealliance/jco/blob/main/package.json#L77, then keeping the normal Jco dependency definition.

@vados-cosmonic
Copy link
Collaborator Author

Yeah that's even better since we're trying to move to workspaces anyway -- thanks for the suggestion

@vados-cosmonic vados-cosmonic force-pushed the examples=add-webidl-example branch from fd4e102 to a23e2ab Compare March 10, 2025 18:14
@vados-cosmonic
Copy link
Collaborator Author

Hey @guybedford actually I don't think this will work -- we don't currently build the local jco to run the examples (we run pretty quickly with the published version) -- cargo and other things for building the local jco package aren't actually present.

What I'm doing is refactoring a bit so we do one build and then re-use it w/ examples. Unfortunately this means main.yml gets longer but it's not outrageous yet.

@vados-cosmonic vados-cosmonic force-pushed the examples=add-webidl-example branch 3 times, most recently from 75e2552 to 31347a3 Compare March 10, 2025 18:49
@vados-cosmonic vados-cosmonic force-pushed the examples=add-webidl-example branch 7 times, most recently from 0a39eb2 to 10572c1 Compare March 10, 2025 19:57
@guybedford
Copy link
Collaborator

I've posted #592 demonstrating just the workspaces part here, rebasing to that might help.

@vados-cosmonic
Copy link
Collaborator Author

vados-cosmonic commented Mar 10, 2025

Yeah, so I tried a bunch of stuff and was able to get it partially working as you did there -- the problems that are left should be trivially fixable, but aren't:

  • Using relative path jco means doing the cargo build in every test area (this lead me to refactor the CI to pass the built package along)
  • Tests (including WebIDL) itself doesn't pickup that version of jco even when I install the local package, and installing it globally (and removing the local devDep) isn't a good solution.
  • Separately, when tests run and pass w/ workspaces, they seem to return a nonzero code (I got this working with the WebIDL example).

I just don't think npm workspaces work very well with how the repo is set up yet -- it's incredibly unintuitive/obvious things don't work on the first try. I'm not sure the juice is worth the squeeze in this particular PR.

Maybe the workspace integration should be handled separately from this ticket -- making it work is introducing a ton of noise, and if someone pulls the repo to run an example I don't think they'd want to do an npm run build + npm install just to run the example in the first place. I intended those examples to be run against the published version so someone could pull and get started easily (jco doesn't have a project-starter templating mechanism yet, but maybe someday)

@guybedford
Copy link
Collaborator

I landed the layering here for workspaces in #592 which should avoid the concerns mentioned.

@vados-cosmonic vados-cosmonic force-pushed the examples=add-webidl-example branch 2 times, most recently from b7bd0bb to 908fcfe Compare March 10, 2025 20:48
This commit adds an example that showcases `webidl2wit` usage to
generate `jco` components.

Signed-off-by: Victor Adossi <[email protected]>
@vados-cosmonic vados-cosmonic force-pushed the examples=add-webidl-example branch from 908fcfe to 30c4d80 Compare March 10, 2025 20:49
@vados-cosmonic vados-cosmonic force-pushed the examples=add-webidl-example branch from e2c536e to d448422 Compare March 10, 2025 21:14
@vados-cosmonic vados-cosmonic force-pushed the examples=add-webidl-example branch from c361ed8 to 742fcd5 Compare March 11, 2025 04:34
@vados-cosmonic vados-cosmonic force-pushed the examples=add-webidl-example branch from c194d9f to 89b4b7b Compare March 11, 2025 07:06
@vados-cosmonic
Copy link
Collaborator Author

Hey @guybedford this should be ready for review now, I've rebased to the workspace integration (thanks!) and tests are 🟢

@guybedford guybedford merged commit e7871a4 into bytecodealliance:main Mar 11, 2025
20 checks passed
@vados-cosmonic vados-cosmonic deleted the examples=add-webidl-example branch March 18, 2025 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants