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

build: fix build on Apple Silicon #123

Merged
merged 2 commits into from Jan 11, 2022
Merged

build: fix build on Apple Silicon #123

merged 2 commits into from Jan 11, 2022

Conversation

tylinux
Copy link
Contributor

@tylinux tylinux commented Jan 1, 2022

Add arm64 to config.sub to support build on Apple Silicon. diff like:

--- a/build-aux/config.sub
+++ b/build-aux/config.sub
@@ -1258,6 +1258,9 @@ case $basic_machine in
 		basic_machine=z80-unknown
 		os=-sim
 		;;
+	arm64-*)
+		basic_machine=$(echo $basic_machine | sed 's/arm64/aarch64/')
+		;;
 	none)
 		basic_machine=none-none
 		os=-none

@lionello
Copy link

lionello commented Jan 4, 2022

I confirmed this works!

@lionello
Copy link

lionello commented Jan 4, 2022

Also see #118

if [[ ("$OSTYPE" == "darwin"*) && ($(uname -m) == "arm64") ]]; then
XZ_SRC_DIR=$(ls | grep xz-*)
sed -i.bak 's/\tnone)/\tarm64-*)\n\t\tbasic_machine=$(echo $basic_machine | sed "s\/arm64\/aarch64\/")\n\t\t;;\n\t\tnone)/g' $XZ_SRC_DIR/build-aux/config.sub
rm $XZ_SRC_DIR/build-aux/config.sub.bak
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could remove this line and the .bak on line 17 (leave -i for in-place replace)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DONE!

@addaleax
Copy link
Owner

addaleax commented Jan 5, 2022

Is this something you have considered submitting upstream? Usually the xz/liblzma maintainer is pretty responsive.

@beorn
Copy link

beorn commented Jan 5, 2022

Is this something you have considered submitting upstream? Usually the xz/liblzma maintainer is pretty responsive.

Even if that was done, can we have a patch for 5.2.3 here to speed things up? It seems like https://tukaani.org/xz/ has a release cadence of years: 5.2.3 was released in 2016, 5.2.4 in 2018, and 5.2.5 in March 2020.

@tylinux
Copy link
Contributor Author

tylinux commented Jan 6, 2022

Is this something you have considered submitting upstream? Usually the xz/liblzma maintainer is pretty responsive.

xz 5.2.3 could be compiled on Apple Silicon devices if we run ./autogen.sh before ./configure, but if I add this to liblzma-config.sh, the script will exit after ./autogen.sh...

beorn added a commit to earlyorbit/lzma-native that referenced this pull request Jan 10, 2022
- `liblzma-config.sh`: Make more robust to failure:
  - Patch for config.sub for Apple Silicon - addaleax#123
  - If configure fails, run autogen.sh / autoconf (*)
- refactor `build` action in `bindings.gyp` so that config and build scripts output is shown, making troubleshooting easier
  - `build` action refactored into `build` and `configure` actions with dependencies between them
  - since `configure` is a separate action instead of a command that runs as part of the 'input' key, it is free to output anything
  - script output is made less verbose and more clear, so it's not necessary to send to log file
- added `manual:config` and `manual:build` targets to `package.json` so it's easier to troubleshoot step-by-step
- for reference, add link to XZ library used to README.md

(*) The drawback of this is that the fallback to autoconf requires a full autoconf type build environment, but it is a last resort fallback.
@beorn
Copy link

beorn commented Jan 10, 2022

Okay, I continued fiddling with #125 following the lead of @tylinux to look into autoconf as well, and and ended up with this algorithm:

  • Apply the patch from this PR
  • Try ./configure
  • Fallback to ./autoconf + ./configure if configure fails (requires a full autoconf dev enviornment)

In addition I did a few refactorings to improve future troubleshooting, in particular the config and build scripts are less verbose and called in a way so that there is no need to send their output to log files (they are separate actions in bindings.gyp).

We're currently on XZ 5.2.3, but XZ 5.2.5 was released two years ago - I tried it, but the config.sub in it also unfortunately doesn't support Apple Silicon. I assume that once XZ 5.3 is released it'll include updated output from autogen.sh and we'll have a working configure setup. That's really the solution - just prod XZ to release a new version and adopt it :)

I guess we still need to create and upload the prebuilds for Apple Silicon - I assume @addaleax needs to do that.

@beorn
Copy link

beorn commented Jan 10, 2022

I submitted a request to the XZ Utils forum. Meanwhile, for proper history and credit, and since it's somewhat urgent,I suggest you accept this PR (#123) and then I can rebase #125 against it so it's just around the (less urgent and less necessary) refactoring work.

@addaleax addaleax merged commit 8af909b into addaleax:main Jan 11, 2022
@addaleax
Copy link
Owner

Thank you @beorn @tylinux @malept for the work here! 8.0.5 was just published with prebuilds for Apple Silicon ✨

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.

None yet

4 participants