From f6f2955d144eb51660f7f4637eba8217b7ea1ddd Mon Sep 17 00:00:00 2001 From: Arun Dhyani Date: Wed, 26 Feb 2025 13:20:59 +0530 Subject: [PATCH 1/3] fix: support added for packages with multiple files in main --- disassembler/objdump/diassembler.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/disassembler/objdump/diassembler.go b/disassembler/objdump/diassembler.go index 78b0846..3c6994e 100644 --- a/disassembler/objdump/diassembler.go +++ b/disassembler/objdump/diassembler.go @@ -7,7 +7,6 @@ import ( "os/exec" "path/filepath" - "github.com/ChainSafe/vm-compat/common" "github.com/ChainSafe/vm-compat/disassembler" ) @@ -66,18 +65,15 @@ func generateSourceAssembly(target string, goos, arch string) (string, error) { return "", err } - // Find the module root of the target file - modRoot, err := common.FindGoModuleRoot(absPath) - if err != nil { - return "", fmt.Errorf("failed to find go module root: %w", err) - } + projectDir := filepath.Dir(absPath) //nolint:gosec - buildCmd := exec.Command("go", "build", "-o", tempFile, absPath) - buildCmd.Dir = modRoot // Set the working directory to the module root + buildCmd := exec.Command("go", "build", "-o", tempFile, "./") + buildCmd.Dir = projectDir // Set the working directory to the main package buildCmd.Env = append(os.Environ(), fmt.Sprintf("GOOS=%s", goos), fmt.Sprintf("GOARCH=%s", arch), + "GO111MODULE=off", ) if arch == "mips" { buildCmd.Env = append(buildCmd.Env, "GOMIPS=softfloat") From 4e328ff60f29fc910ea4ced145c4803a0d169f15 Mon Sep 17 00:00:00 2001 From: Arun Dhyani Date: Wed, 26 Feb 2025 13:22:06 +0530 Subject: [PATCH 2/3] renaming --- disassembler/objdump/diassembler.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/disassembler/objdump/diassembler.go b/disassembler/objdump/diassembler.go index 3c6994e..cbb88b3 100644 --- a/disassembler/objdump/diassembler.go +++ b/disassembler/objdump/diassembler.go @@ -65,11 +65,11 @@ func generateSourceAssembly(target string, goos, arch string) (string, error) { return "", err } - projectDir := filepath.Dir(absPath) + mainPackageDir := filepath.Dir(absPath) //nolint:gosec buildCmd := exec.Command("go", "build", "-o", tempFile, "./") - buildCmd.Dir = projectDir // Set the working directory to the main package + buildCmd.Dir = mainPackageDir // Set the working directory to the main package buildCmd.Env = append(os.Environ(), fmt.Sprintf("GOOS=%s", goos), fmt.Sprintf("GOARCH=%s", arch), From fae60f26c4cf916f71ddbaafa28b0d27527d68ec Mon Sep 17 00:00:00 2001 From: Arun Dhyani Date: Wed, 26 Feb 2025 15:19:18 +0530 Subject: [PATCH 3/3] test cases pushed --- e2e_tests/testdata/hello/go.mod | 3 +++ e2e_tests/testdata/hello/hello.go | 7 +++++++ e2e_tests/testdata/hello/main.go | 5 +++++ 3 files changed, 15 insertions(+) create mode 100644 e2e_tests/testdata/hello/go.mod create mode 100644 e2e_tests/testdata/hello/hello.go create mode 100644 e2e_tests/testdata/hello/main.go diff --git a/e2e_tests/testdata/hello/go.mod b/e2e_tests/testdata/hello/go.mod new file mode 100644 index 0000000..853b93f --- /dev/null +++ b/e2e_tests/testdata/hello/go.mod @@ -0,0 +1,3 @@ +module hello + +go 1.22.2 diff --git a/e2e_tests/testdata/hello/hello.go b/e2e_tests/testdata/hello/hello.go new file mode 100644 index 0000000..f4adb47 --- /dev/null +++ b/e2e_tests/testdata/hello/hello.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func hello() { + fmt.Println("Hello World!") +} diff --git a/e2e_tests/testdata/hello/main.go b/e2e_tests/testdata/hello/main.go new file mode 100644 index 0000000..0a4df15 --- /dev/null +++ b/e2e_tests/testdata/hello/main.go @@ -0,0 +1,5 @@ +package main + +func main() { + hello() +}