xgo: go: go.mod file not found in current directory or any parent directory

I get:

go: go.mod file not found in current directory or any parent directory

However:

bash-3.2$ ls go.mod
go.mod

The command:

xgo -x --deps https://www.sqlite.org/2020/sqlite-autoconf-3320300.tar.gz --depsargs '--disable-fts4 --disable-fts5 --disable-rtree --disable-static-shell' --pkg internal/log_analysis/datalake/database_api/snowflake/driver/main --targets=linux/amd64 -out main --tags 'libsqlite3 linux' -dest out/bin/internal/log_analysis/datalake/database_api/snowflake/driver/main .

Any ideas?

This worked with go 1.13 but now I have to move to 1.16 because of other changes in the code base.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 23 (8 by maintainers)

Commits related to this issue

Most upvoted comments

oh darn, thanks for letting me know. I’ve reopened this so I can look into it.

Hi @techknowlogick @rleighton I’ve hit this issue too – seems to be a 6 line fix. I’d push a PR but don’t have the permissions.

Here’s a git patch:

From b81da5dd77c6d0934d7a79064a6c287bba6f0ee9 Mon Sep 17 00:00:00 2001
From: serbantanasa <serban.tanasa@xxxxx.xx>
Date: Tue, 23 Mar 2021 12:56:04 -0400
Subject: [PATCH] fix xgo issue
​
---
 xgo.go | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
​
diff --git a/xgo.go b/xgo.go
index a341db0..a6f46bc 100644
--- a/xgo.go
+++ b/xgo.go
@@ -255,19 +255,18 @@ func compile(image string, config *ConfigFlags, flags *BuildFlags, folder string
 	locals, mounts, paths := []string{}, []string{}, []string{}
 	var usesModules bool
 	if strings.HasPrefix(config.Repository, string(filepath.Separator)) || strings.HasPrefix(config.Repository, ".") {
-		// Resolve the repository import path from the file path
-		config.Repository = resolveImportPath(config.Repository)
-
-		// Determine if this is a module-based repository
-		var modFile = config.Repository + "/go.mod"
-		_, err := os.Stat(modFile)
-		usesModules = !os.IsNotExist(err)
+		if _, err := os.Stat(config.Repository + "/go.mod"); err == nil {
+			usesModules = true
+		}
 
 		// Iterate over all the local libs and export the mount points
 		if os.Getenv("GOPATH") == "" && !usesModules {
 			log.Fatalf("No $GOPATH is set or forwarded to xgo")
 		}
 		if !usesModules {
+			// Resolve the repository import path from the file path
+			config.Repository = resolveImportPath(config.Repository)
+
 			for _, gopath := range strings.Split(os.Getenv("GOPATH"), string(os.PathListSeparator)) {
 				// Since docker sandboxes volumes, resolve any symlinks manually
 				sources := filepath.Join(gopath, "src")
-- 
2.24.3 (Apple Git-128)
​

Awesome, thanks 😃 Let me try to put this together as a PR.

Closing as linked PR has now been merged. Will be a sec before CI builds/publishes the new images.