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

feat: support building AO wasm module with Rust code #1122

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

RyanKung
Copy link
Contributor

@RyanKung RyanKung commented Jan 19, 2025

TL;DR

It implements the functionality of compiling Rust code into the AO_WASM-compatible format. The principle is to use FFI to bridge Rust and C, allowing C code to directly call Rust and enabling compilation into WASM within a Docker image.

Note: This PR is based on the following PRs.
#1121
#1119

This PR has not undergone comprehensive testing. If you wanna to try it out, please carefully review the relevant code. If you encounter any issues, feel free to make modifications based on this branch.

How to use

  1. At ao/dev-cli/container:
    Run bash.sh to build your custom Image

  2. At src/starters/rust
    Run ao build --image docker.io/p3rmaw3b/ao to build.

Key features / changes:

  1. dev-cli/container/Dockerfile
  • Added script to install rust environment.
  • Removed trail whitespace
  1. dev-cli/container/src/ao-build-module
  • Removed trail whitespace
  • Modified rust build cmd cmd.extend(['-I/opt/aorustlib', '-L/opt/aorustlib', '-laorust'])
  1. dev-cli/container/src/ao_module_lib/languages/rust.py
  • Just build rust code inside /src, then move headers and staticlib to '/opt/aorustlib'
  1. dev-cli/src/starters/rust
  • Rust code starter, support local building

@RyanKung RyanKung changed the title feat: support building ao wasm with Rust feat: support building ao wasm with Rust code Jan 19, 2025
@RyanKung RyanKung changed the title feat: support building ao wasm with Rust code feat: support building ao wasm file with Rust code Jan 19, 2025
@RyanKung RyanKung changed the title feat: support building ao wasm file with Rust code feat: support building AO wasm module with Rust code Jan 19, 2025
@RyanKung
Copy link
Contributor Author

RyanKung commented Jan 20, 2025

Update, we now have issues:

[wasm-validator error in function _$LT$$RF$T$u20$as$u20$core..fmt..Debug$GT$::fmt::hea3ded4c73476728] i64 != i32: indirect call target must be an i32, on
(call_indirect $0 (type $func.0)
 (i64.load
  (local.get $0)
 )
 (local.get $1)
 (i64.load offset=24
  (i64.load offset=8
   (local.get $0)
  )
 )
)

Looks like the call_indirect of core::fmt::Debug failed to compile into i32.

@RyanKung
Copy link
Contributor Author

Update, we now have issues:

[wasm-validator error in function _$LT$$RF$T$u20$as$u20$core..fmt..Debug$GT$::fmt::hea3ded4c73476728] i64 != i32: indirect call target must be an i32, on
(call_indirect $0 (type $func.0)
 (i64.load
  (local.get $0)
 )
 (local.get $1)
 (i64.load offset=24
  (i64.load offset=8
   (local.get $0)
  )
 )
)

Looks like the call_indirect of core::fmt::Debug failed to compile into i32.

Fixed by set target=32 in src/config.yaml

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.

1 participant