go mod vendor integration is still broken for rtmididriv
As I said earlier, you may need to add a dummy .go file to the cpp/ directory, in order for go mod vendor to avoid accidentally deleting the critical cpp/ directory.
Go is very strict about deleting directories that lack .go source files. So Cgo projects need to create some dummy files to stop that from breaking downstream Go builds.
$ cat go.mod
module github.com/mcandre/octane
go 1.16
require (
github.com/magefile/mage v1.11.0
github.com/mcandre/mage-extras v0.0.7
gitlab.com/gomidi/midi/v2 v2.0.25
)
$ go install ./...
# gitlab.com/gomidi/midi/v2/drivers/rtmididrv/imported/rtmidi
In file included from vendor/gitlab.com/gomidi/midi/v2/drivers/rtmididrv/imported/rtmidi/rtmidi.go:16:
./rtmidi_stub.h:1:10: fatal error: 'cpp/rtmidi_c.h' file not found
#include "cpp/rtmidi_c.h"
^~~~~~~~~~~~~~~~
1 error generated.
Workaround 1
As a simple workaround, I am tempted to skip the go mod vendor step.
However, this has the side effect of breaking whenever a dependency changes upstream. And gomid has a history of doing exactly that, to the point of even 404ing old repositories.
Workaround 2
The modvendor tool can re-add C/C++ files.
https://github.com/goware/modvendor
$ go mod vendor
$ go mod tidy
$ modvendor -copy='**/*.h **/*.c **/*.hpp **/*.cpp'
For example, with my octane MIDI note transposer application:
https://github.com/mcandre/octane
That's better, though it's still hacky and may break if the underlying go mod system changes in the future.
Ideally, I understand that the files in cpp/ just need to be moved to a flatter directory structure, so that all .h, .c, .hpp, .cpp files have a sibling .go file. Then the driver cgo projects will finally integrate with go mod vendor properly.