This patch introduces a new build tag `nolibopusfile` that conditionally
compiles out the code that imports `libopusfile`. This enables a static
binary build on Alpine Linux, which doesn’t have a static `libopusfile`.
Tests still work:
```sh
go test -tags nolibopusfile ./...
go test ./...
```
We could also have moved all libopusfile related code (i.e. Stream) into
a separate sub-package, but that would break backwards compatibility.
This feature is too unpopular to justify introducing a new major
version.
See also: https://github.com/hraban/opus/pull/24
Since we now have a full function wrapper for libopusfile init anyway we
can directly pass the callback struct pointer from there, instead of
making it go through Go first.
Since go 1.14 the race checker includes an overzealous pointer checker.
It marks all conversions from uintptr to unsafe.Pointer as an error, but
in reality that's allowed as long as you never dereference the pointer
or do any arithmetic on it. The C compiler doesn't complain about this,
so we pass the uintptr value to C and convert it there, in a small
wrapper function.
See https://groups.google.com/g/golang-nuts/c/995uZyRPKlU for more
details.
Fixeshraban/opus#28
I'm not sure if the Go pointer proposal has already been implemented,
but under the proposed restrictions allocating the callback struct in Go
and passing that pointer to a C function which keeps it after returning
is not allowed.
This patch allocates the struct in C and passes the pointer from Go to
C, which is fine.