Skip to content

feat: replace TinyGo with standard Go for WebAssembly modules #8496

New issue

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

By clicking “No 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? No Sign in to your account

Merged
merged 15 commits into from
Mar 7, 2025

Conversation

knqyf263
Copy link
Collaborator

@knqyf263 knqyf263 commented Mar 5, 2025

Description

Go 1.24 improved Wasm support. We can directly compile Go code into Wasm modules without TinyGo.
https://go.dev/blog/wasmexport

  • Update module documentation to reflect Go support instead of TinyGo
  • Modify build commands to use standard Go for WebAssembly compilation
  • Remove TinyGo-specific code and comments
  • Update WASM SDK to work with standard Go
  • Remove TinyGo-specific UUID implementation
  • Update build scripts and example modules to use Go build

Related PRs

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

- Update module documentation to reflect Go support instead of TinyGo
- Modify build commands to use standard Go for WebAssembly compilation
- Remove TinyGo-specific code and comments
- Update WASM SDK to work with standard Go
- Remove TinyGo-specific UUID implementation
- Update build scripts and example modules to use Go build
@knqyf263 knqyf263 self-assigned this Mar 5, 2025
knqyf263 added 2 commits March 6, 2025 10:09
- Add explicit memory management for WASM module function calls
- Implement deferred pointer freeing for dynamically allocated memory
- Add comments explaining memory allocation and freeing responsibilities
- Refactor module functions to consistently handle memory allocation
- Improve error handling and resource management in WASM module interactions
@knqyf263 knqyf263 changed the title feat(module): replace TinyGo with standard Go for WebAssembly modules feat: replace TinyGo with standard Go for WebAssembly modules Mar 6, 2025
knqyf263 added 6 commits March 6, 2025 11:34
- Move artifact type constants from `artifact` package to `fanal/types`
- Update all references to use `ftypes.ArtifactType` instead of `artifact.Type`
- Remove redundant type definition in `artifact` package
- Ensure consistent usage of artifact type across the project
- Improve type safety and reduce package dependencies
- Replace custom serialization types with standard `types.Results`
- Update module interfaces to use `types.Results` instead of `serialize.Results`
- Remove redundant type definitions in `serialize` package
- Simplify type imports and reduce package complexity
- Improve compatibility with standard Go WebAssembly modules
- Replace `serialize.CustomResource` with `ftypes.CustomResource`
- Update Spring4Shell module to use `ftypes.CustomResource`
- Remove redundant type definition in `serialize` package
- Improve type consistency across module and fanal packages
- Clean up unnecessary dependencies in go.mod and go.sum
- Remove tools and packages no longer used in the project
- Simplify dependency management by removing redundant entries
- Reduce project complexity and potential version conflicts
- Replace `serialize.Results` with `types.Results` in module test files
- Update import statements to use `types.Results`
- Maintain consistency with previous type migration efforts
- Simplify type imports for module test data
@@ -86,23 +86,10 @@ type Artifact interface {
Clean(reference Reference) error
}

// Type represents a type of artifact
type Type string
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

artifact package imports many other modules, which cannot be compiled to Wasm. I moved this type to fanal/types so Wasm modules will not import artifact.

- Ensure proper database connection closure after test
- Use `t.Cleanup()` to automatically close database connection
- Improve test resource management and prevent potential resource leaks
@knqyf263 knqyf263 marked this pull request as ready for review March 6, 2025 10:42
@knqyf263 knqyf263 requested a review from DmitriyLewen as a code owner March 6, 2025 10:42
Copy link
Contributor

@DmitriyLewen DmitriyLewen left a comment

Choose a reason for hiding this comment

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

LGTM.

Left small comments about docs


### TinyGo
### Go
Copy link
Contributor

Choose a reason for hiding this comment

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

update PostScan(serialize.Results) (serialize.Results, error) to PostScan(results types.Results) (types.Results, error) bellow.

Copy link
Contributor

Choose a reason for hiding this comment

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

PostScan(serialize.Results) (serialize.Results, error)

`serialize.Results` contains the filtered results matching IDs you specified.

func (WordpressModule) PostScan(results serialize.Results) (serialize.Results, error) {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for catching them.
4ff9d71

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can add the following code here

// main is required for Go to compile the Wasm module
func main() {}

Copy link
Collaborator Author

@knqyf263 knqyf263 Mar 7, 2025

Choose a reason for hiding this comment

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

Agree. I added it here.
c481d0d

knqyf263 added 3 commits March 7, 2025 10:17
- Replace `serialize.Results` with `types.Results` in Wordpress module
- Update `PostScan` method to use `types.Results`
- Migrate custom resources to use `ftypes.CustomResource`
- Simplify type imports and improve package consistency
- Add empty `main()` function to enable Go Wasm module compilation
- Ensure compatibility with Go Wasm module requirements
- Minimal change to support WebAssembly module generation
Copy link
Contributor

@DmitriyLewen DmitriyLewen left a comment

Choose a reason for hiding this comment

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

LGTM

@DmitriyLewen DmitriyLewen enabled auto-merge March 7, 2025 06:24
knqyf263 added 2 commits March 7, 2025 12:26
- Replace `os.Remove()` with `f.Close()` in temporary file tests
- Ensure proper file resource management in test cases
- Prevent potential resource leaks by using `defer f.Close()`
- Close temporary source file in CopyFile test
- Prevent potential resource leaks by calling `s.Close()`
- Improve file resource management in test case
@DmitriyLewen DmitriyLewen added this pull request to the merge queue Mar 7, 2025
Merged via the queue into aquasecurity:main with commit 529957e Mar 7, 2025
17 checks passed
@aqua-bot aqua-bot mentioned this pull request Mar 7, 2025
@knqyf263 knqyf263 deleted the go_wasm branch March 10, 2025 05:31
No Sign up for free to join this conversation on GitHub. Already have an account? No Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants