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

support cross-compilation of stylus programs #2605

Merged
merged 27 commits into from
Sep 4, 2024
Merged

support cross-compilation of stylus programs #2605

merged 27 commits into from
Sep 4, 2024

Conversation

magicxyyz
Copy link
Contributor

@cla-bot cla-bot bot added the s Automatically added by the CLA bot if the creator of a PR is registered as having signed the CLA. label Aug 22, 2024
@magicxyyz magicxyyz marked this pull request as ready for review August 26, 2024 17:12
Copy link
Contributor

@tsahee tsahee left a comment

Choose a reason for hiding this comment

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

small comments

results := make(chan result, len(targets))
for _, target := range targets {
if target == rawdb.TargetWavm {
results <- result{target, module, nil}
Copy link
Contributor

Choose a reason for hiding this comment

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

compile wavm before the loop. If it fails - return just that error without trying other compilation. If it succeeds add wavm to the map and do the loop. Inside the loop - skip wavm compilation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wavm is compiled before the loop iterating over targets and if wavm compilation fails we return error:

status_mod := userStatus(C.stylus_activate(
goSlice(wasm),
u16(page_limit),
u16(version),
cbool(debug),
output,
&codeHash,
moduleHash,
stylusData,
(*u64)(gasLeft),
))
module, msg, err := status_mod.toResult(output.intoBytes(), debug)
if err != nil {
if debug {
log.Warn("activation failed", "err", err, "msg", msg, "program", addressForLogging)
}
if errors.Is(err, vm.ErrExecutionReverted) {
return nil, nil, fmt.Errorf("%w: %s", ErrProgramActivation, msg)
}
return nil, nil, err
}

I add compiled module to results channel in the loop to add it to asmMap later on only if rawdb.TargetWavm is in the targets list. That way the code is ready for not storing wavm if not needed.
Does it sound right?

I can change it to always include wavm compilation output in the resulting asmMap, but I think that it is enough to require Wavm in WasmTargets list to have it always stored in db in this version.

let me know what you think

arbos/programs/native.go Outdated Show resolved Hide resolved
cmd/nitro/init_test.go Outdated Show resolved Hide resolved
execution/gethexec/executionengine.go Show resolved Hide resolved
execution/gethexec/node.go Show resolved Hide resolved
@magicxyyz magicxyyz requested a review from tsahee August 28, 2024 12:38
tsahee
tsahee previously approved these changes Aug 29, 2024
Copy link
Contributor

@tsahee tsahee left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@tsahee tsahee left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@tsahee tsahee left a comment

Choose a reason for hiding this comment

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

LGTM

@tsahee tsahee merged commit 3e673d4 into master Sep 4, 2024
14 checks passed
@tsahee tsahee deleted the cross-compile branch September 4, 2024 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design-approved s Automatically added by the CLA bot if the creator of a PR is registered as having signed the CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants