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

Makefile: export GOARCH, GOOS #3275

Merged
merged 1 commit into from
Apr 16, 2024
Merged

Makefile: export GOARCH, GOOS #3275

merged 1 commit into from
Apr 16, 2024

Conversation

pronebird
Copy link
Contributor

@pronebird pronebird commented Apr 16, 2024

On macOS it's possible to compile both x86_64 and aarch64 binaries and then merge them together to produce universal build. It doesn't seem possible to achieve without passing GOARCH and GOOS into the go build command, so this PR re-exports those env variables and tweaks the binary name to reflect the architecture.

Example usage:

XRAY_SRC_DIR="<path to xray-core checkout>"

GOOS=darwin GOARCH=amd64 make -C "$XRAY_SRC_DIR"
GOOS=darwin GOARCH=arm64 make -C "$XRAY_SRC_DIR"

local amd64_bin="$XRAY_SRC_DIR/xray-amd64"
local arm64_bin="$XRAY_SRC_DIR/xray-arm64"
local fat_bin="$XRAY_SRC_DIR/xray"

lipo -create "$amd64_bin" "$arm64_bin" -output "$fat_bin"

@yuhan6665 yuhan6665 merged commit befa7b8 into XTLS:main Apr 16, 2024
@yuhan6665
Copy link
Member

Thanks!

@pronebird pronebird deleted the patch-1 branch April 16, 2024 15:13
@RPRX
Copy link
Member

RPRX commented Apr 26, 2024

On macOS it's possible to compile both x86_64 and aarch64 binaries and then merge them together to produce universal build. It doesn't seem possible to achieve without passing GOARCH and GOOS into the go build command, so this PR re-exports those env variables and tweaks the binary name to reflect the architecture.

我查了一下,makefile 的 export 应写在主 makefile 中,仅用于将变量传递给子 makefile,所以在这个最终的 makefile 中写 export 是没有意义的。其次,你可以 make 后再修改 xray 为其它名称,不必改 makefile。(或者 NAME ?= xray?)

综上,我将 revert 这个 PR,期待你的下次贡献。

RPRX added a commit that referenced this pull request Apr 26, 2024
@pronebird
Copy link
Contributor Author

@RPRX i am not sure what main makefile you refer to. I run make directly on your repo, so that’s unfortunate this is being reversed. I can certainly rename the built binary manually but I can’t pass GO env otherwise. Please advise.

@RPRX
Copy link
Member

RPRX commented Apr 26, 2024

but I can’t pass GO env

Please recheck that.

@pronebird
Copy link
Contributor Author

but I can’t pass GO env

Please recheck that.

I can't believe I had missed it. Indeed works fine when running make with GOOS and GOARCH set.

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 this pull request may close these issues.

3 participants