doronbehar / pistol

General purpose file previewer designed for Ranger, Lf to make scope.sh redundant

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add make variables for Mac OS 12.5/ARM

joshfrench opened this issue · comments

Env:

go version go1.19 darwin/arm64
OS: macOS Monterey 12.5

I've previously installed Pistol on OS 11.6/Intel with no issues, but on a new machine I'm unable to install or build it.

Steps:

$ brew install libmagic
...
(installation succeeds)

$ brew link libmagic
Already linked: /opt/homebrew/Cellar/libmagic/5.42

$ go install github.com/doronbehar/pistol/cmd/pistol@v0.3.2
../../go/pkg/mod/github.com/doronbehar/magicmime@v0.1.1-0.20211127135329-3de4ff29dc49/magicmime.go:28:11: fatal error: 'magic.h' file not found

$ CGO_CFLAGS="-I${HOMEBREW_PREFIX}/Cellar/libmagic/5.42/include" go install github.com/doronbehar/pistol/cmd/pistol@v0.3.2
/opt/homebrew/Cellar/go/1.19/libexec/pkg/tool/darwin_arm64/link: running clang failed: exit status 1
ld: library not found for -lmagic
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I get the last error (ld: library not found for -lmagic) when attempting to build from source, as well.

I'm mostly posting this in case other OS X users run into it -- the problem seems to be with libmagic, and I suspect you're unable to help troubleshoot OS X anyway :)

Aha! I needed to pass another flag when building:

CGO_CFLAGS="-I${HOMEBREW_PREFIX}/include" CGO_LDFLAGS="-L${HOMEBREW_PREFIX}/lib" go build

Aha! I needed to pass another flag when building:

CGO_CFLAGS="-I${HOMEBREW_PREFIX}/include" CGO_LDFLAGS="-L${HOMEBREW_PREFIX}/lib" go build

Do you think @joshfrench this could be empbedded into the makefile? I mean, could we detect that we are building on a macos machine, and add these flags automatically?

You could shell out and check uname -sp (although I'm not sure if -p is present on every platform, so maybe a combination of uname and arch?)

Either way you're looking for Darwin and one of x86_64 or arm64. It's been a while but I think pistol built fine on a previous Intel mac, so you'd only need to add the flags when you detect an Apple chip.

I'd send a PR but my make syntax is pretty rusty :)

Hey, you may want to check the new 0.4.1 release which not necessarily include many new features, but it does include statically compiled binary for aarch64. I still think this issue is worth staying open, for any Mac OS user that will want to build and help develop pistol in the future, so I'm keeping this open.