eraserhd / parinfer-rust

A Rust port of parinfer.
ISC License
546 stars 42 forks source link

Build fails on Mac M1 #94

Closed dharrigan closed 3 years ago

dharrigan commented 3 years ago

Hi,

❯ cargo --version
cargo 1.49.0 (d00d64df9 2020-12-05)
❯ clang --version
Apple clang version 12.0.0 (clang-1200.0.32.28)
Target: arm64-apple-darwin20.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
  ~/.vim/bundle/parinfer-rust on   master
❯ git log
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
commit 998484ba3ca9c162971e3fa6f01e67cc3e9ac85e (HEAD -> master, origin/master, origin/HEAD) ┃
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
Merge: d7d1c4f f2fe726
Author: Jason Felice <jason.m.felice@gmail.com>
Date:   Oct 26 2020

    Merge pull request #88 from avrma-forks/os_detection_performance

    plugin: optimize OS detection logic for Neovim.

When attempting to build, I'm receiving this error:


  ~/.vim/bundle/parinfer-rust on   master                                                                                                                                                              ▼
❯ RUST_BACKTRACE=full cargo build --release
   Compiling emacs_module v0.10.0
error: failed to run custom build command for `emacs_module v0.10.0`

Caused by:
  process didn't exit successfully: `/Users/david/.vim/bundle/parinfer-rust/target/release/build/emacs_module-98c38d7004bf7081/build-script-build` (exit code: 101)
  --- stderr
  thread 'main' panicked at 'libclang error; possible causes include:
  - Invalid flag syntax
  - Unrecognized flags
  - Invalid flag arguments
  - File I/O errors
  If you encounter an error missing from this list, please file an issue or a PR!', /Users/david/.cargo/registry/src/github.com-1ecc6299db9ec823/bindgen-0.48.1/src/ir/context.rs:568:15
  stack backtrace:
     0:        0x100cd86b0 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hb7980d26174b99cc
     1:        0x100cf60a4 - core::fmt::write::hce37a9344a9aa8e7
     2:        0x100cd55a0 - std::io::Write::write_fmt::h686eb8440ccc31c3
     3:        0x100cda4f4 - std::panicking::default_hook::{{closure}}::hd8ecce238a238901
     4:        0x100cda1cc - std::panicking::default_hook::h4c3bbdaeee039651
     5:        0x100cdaaa8 - std::panicking::rust_panic_with_hook::h140cbf507d3407f4
     6:        0x100cda684 - std::panicking::begin_panic_handler::{{closure}}::hb6a3220cf34e266a
     7:        0x100cd8b68 - std::sys_common::backtrace::__rust_end_short_backtrace::hd5353dc16fba6ea5
     8:        0x100cda5ec - _rust_begin_unwind
     9:        0x100cffa8c - core::panicking::panic_fmt::h0333f3235caab578
    10:        0x100cff98c - core::option::expect_failed::hf0ddc7de4cc4d418
    11:        0x10097e8d0 - core::option::Option<T>::expect::h6de67e19242853af
    12:        0x1009231d0 - bindgen::ir::context::BindgenContext::new::h6fd00c26b56ccaee
    13:        0x10091c1a8 - bindgen::Bindings::generate::h9f2a5de16c64899d
    14:        0x10091a398 - bindgen::Builder::generate::h4e79d60cc5e22c5c
    15:        0x1008a3d54 - build_script_build::main::hee199bae0c1d1ea7
    16:        0x1008a30a8 - core::ops::function::FnOnce::call_once::h59e4f01232c53b8c
    17:        0x1008a31f8 - std::sys_common::backtrace::__rust_begin_short_backtrace::h47c9f856bce77654
    18:        0x1008a4130 - std::rt::lang_start::{{closure}}::hb661c587eddb9b76
    19:        0x100cdaf00 - std::rt::lang_start_internal::h1c29856da483cadc
    20:        0x1008a410c - std::rt::lang_start::he31fbf461510c46e
    21:        0x1008a3e74 - _main```
stefanvanburen commented 3 years ago

if you're not going to use the emacs portion of the binary, I've had luck removing it and compiling it on my M1.

basically, cargo rm emacs (you might need cargo-edit) and then edit src/lib.rs and remove the emacs portions.

dharrigan commented 3 years ago

Hi,

Thank you for that, it certainly helps! However, it does leave the repo unmanaged by vim plug, as there are local modifications. I hope that a long term solution can be done put into place eventually :-)

Thank you once again! :-)

eraserhd commented 3 years ago

The emacs crate has been a huge pain in terms of dependencies. I wonder if it's possible to replace it with something like in Vim, where a native C function is called.

dharrigan commented 3 years ago

Hi,

Okay, determined not to give up, I got it working via these means...

  1. Updated dependencies by running cargo update
  2. Discovered there is a new version of emacs module that has a fix, not yet merged in so...
  3. Cloned this repo https://github.com/nwjsmith/emacs-module-rs.git
  4. Checked out his fix support-aarch64-apple-darwin
  5. Ensured that it built cargo build --release
  6. Updated parinfer-rust Cargo.toml to use this new repo:
#emacs = "0.16.0"
emacs = { path = "/Users/david/tmp/emacs-module-rs" }
  1. Added in in the x86_64-apple-darwin architecture rustup target add x86_64-apple-darwin
  2. Built parinfer-rust cargo build --release --target=x86_64-apple-darwin
  3. Renamed and linked in the release:
 ~/.vim/bundle/parinfer-rust/target on  master !2                                                                                                                                                    ▼
❯ mv release/ release-bak

 ~/.vim/bundle/parinfer-rust/target on  master !2                                                                                                                                                    ▼
❯ ln -s x86_64-apple-darwin/release

 ~/.vim/bundle/parinfer-rust/target on  master !2                                                                                                                                                    ▼
❯ dir
total 4.0K
-rw-r--r-- 1 david staff 177 Feb 20 10:17 CACHEDIR.TAG
lrwxr-xr-x 1 david staff  27 Feb 20 10:18 release -> x86_64-apple-darwin/release
drwxr-xr-x 8 david staff 256 Feb 20 10:17 release-bak
drwxr-xr-x 4 david staff 128 Feb 20 10:17 x86_64-apple-darwin

Loaded up vim with a Clojure file and parinfer worked!

Joy!

I hope this helps anyone else. I'm not a rustarian(?) so perhaps the steps above can be refined. I leave it to rust experts to work it out.

I think when this https://github.com/ubolonton/emacs-module-rs/pull/38 is merged into the rust emacs module can be upgraded.

-=david=-

bhurlow commented 3 years ago

@dharrigan this worked for me, thanks for posting this here! I believe they are referred to as rustaceans :)

dharrigan commented 3 years ago

Hi,

I just tested this out with the new updates and appears to work once again. Well done! I think this issue can be resolved now :-D

-=david=-