Skip to content

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

@lcsh0s
Copy link

lcsh0s commented Mar 17, 2025

will this be merged any time soon? doesnt seem to be tagged for release

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