Skip to content

Build error on recent go versions (go: cannot find main module, but found .git/config), with workaround #7

Open
@juozaspo

Description

Trying to build on Ubuntu 22.04 LTS I get an error when building using go 1.18.1.
Build log using custom build script:

go clean
go build -ldflags "-X main.Version=4 -X main.Build=`git describe --tags --always`" -o mtmapprune
go: cannot find main module, but found .git/config in /home/juozas/mtmapprune
	to create a module there, run:
	go mod init
make: *** [Makefile:11: mtmapprune] Error 1

Script contents:

#!/bin/bash
# custom build script made by juozaspo, workaround for minetest-tools/mtmapprune#1
make clean
GOPATH=/usr/share/gocode make

Running go mod init github.com/minetest-tools/mtmapprune succeeds but then build fails with error go: could not create module cache: mkdir /usr/share/gocode/pkg: permission denied unless I change the go path. Also the global path in /usr/share/gocode cannot be used as build process tries to write there, and the building takes more time than expected, sqlite library must be installed using command go get github.com/mattn/go-sqlite3.

golang-go package is installed, golang-github-mattn-go-sqlite3-dev appears to be no longer needed, also the readme does not describe what other dependencies are needed, also there are a few new files created by commands above (go mod init, go get), for now I've added them to .gitignore on my fork.

$ cat go.mod 
module github.com/minetest-tools/mtmapprune

go 1.18

require github.com/mattn/go-sqlite3 v1.14.15 // indirect
$ cat go.sum 
github.com/mattn/go-sqlite3 v1.14.15 h1:vfoHhTN1af61xCRSWzFIWzx2YskyMTwHLrExkBOjvxI=
github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=

My updated fork: https://github.com/juozaspo/mtmapprune, with default branch set to testing, with go path removed from build script

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions