-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Conversation
- 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
- 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
- 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 |
There was a problem hiding this comment.
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
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trivy/docs/docs/advanced/modules.md
Line 116 in 0d50527
PostScan(serialize.Results) (serialize.Results, error) |
trivy/docs/docs/advanced/modules.md
Line 239 in 0d50527
`serialize.Results` contains the filtered results matching IDs you specified. |
trivy/docs/docs/advanced/modules.md
Line 249 in 0d50527
func (WordpressModule) PostScan(results serialize.Results) (serialize.Results, error) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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() {}
There was a problem hiding this comment.
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
- 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
- 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
Description
Go 1.24 improved Wasm support. We can directly compile Go code into Wasm modules without TinyGo.
https://go.dev/blog/wasmexport
Related PRs
Checklist