Using custom provider gives "exec format error" error

I’m trying to modify an open source provider for use inside my organization. I’ve built the binary for both darwin and linux amd64 provider platforms, and have uploaded them to our private TFC registry. When I then use Terraform CLI on either of these platforms, the provider is downloaded with “terraform init”, but I get the same error when using “terraform plan”:

│ Error: Failed to load plugin schemas
│ Error while loading schemas for plugin components: Failed to obtain provider schema: Could not load the schema for provider<org>/kong: failed to instantiate provider
│ "<org>/kong" to obtain schema: fork/exec .terraform/providers/<org>/kong/1.0.0/darwin_amd64/terraform-provider-kong_v1.0.0: exec format error..

I get the same error trying it on Ubuntu. I built the binary with the same Go arguments on each platform, based on an online post I saw from someone else getting the same error:

CGO_ENABLED=0 GOOS=<OS> GOARCH=amd64 go build -a -ldflags '-w -extldflags "-static"' -o terraform-provider-kong ./kong

When I look at the binary downloaded into the .terraform directory structure, they appear to be for the right platform (so I didn’t mix up the Zip files I uploaded to the registry), e.g. on macOS:

__.PKGDEF       0           0     0     644     184111    `
go object darwin amd64 go1.19.13 X:regabiwrappers,regabiargs

Any suggestions on how to debug this?

Found I was compiling it incorrectly. Reverted to a simple go build -o <binary name> . and that seemed to resolve it.