Skip to content
New issue

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

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

Building with --pkg names the executable after the module instead of the package #174

Closed
darcys22 opened this issue Oct 30, 2022 · 1 comment · Fixed by #194
Closed

Building with --pkg names the executable after the module instead of the package #174

darcys22 opened this issue Oct 30, 2022 · 1 comment · Fixed by #194

Comments

@darcys22
Copy link

My project defines the module in go.mod

module github.com/darcys22/godbledger

and I have subdirectories for each executable

root
 - go.mod
 - godbledger/
   - main.go
 - reporter/
   - main.go 

When running xgo like this to build each executable using the --pkg parameter:

/home/sean/godbledger/build/bin/xgo --go=go-1.19.x --targets linux/386 --dest /home/sean/godbledger/build/dist/linux-386 -v --pkg reporter .

The name of the executable will be godbledger, not reporter

sean@sean-B550-AORUS-PRO-AX:~/godbledger/build/dist/linux-386/github.com/darcys22$ ls
godbledger-linux-386

It looks like the cause of this is in the build.sh where $NAME is changed if $USEMODULES = true

# Configure some global build parameters
NAME=`basename $1/$PACK`

# Go module-based builds error with 'cannot find main module'
# when $PACK is defined
if [[ "$USEMODULES" = true ]]; then
  NAME=`sed -n 's/module\ \(.*\)/\1/p' /source/go.mod`
fi

Unsure if I am using xgo incorrectly here (or even the modules structure tbh) but the readme makes it look like this should be the name of the executable

@zeripath
Copy link
Collaborator

So the code was recently changed, but it still effectively does the same thing.

Looking at this code again I agree this algorithm is incorrect, but it's not necessarily well defined as to what it should be.

I'll include a fix for this in the big PR I'm working on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants