desbma / rsop

Simple, fast & configurable tool to open and preview files
MIT License
22 stars 3 forks source link

Q: How to build on macOS? #3

Closed ryuheechul closed 1 year ago

ryuheechul commented 1 year ago

I'm currently trying to see if I can build this on macOS.

At the moment I'm testing this using nix below.

# based on the example code from the link below
# https://github.com/NixOS/nixpkgs/blob/645bc49f34fa8eff95479f0345ff57e55b53437e/pkgs/tools/misc/hexyl/default.nix

# more info on rust + nix can be found at
# https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/rust.section.md
{ pkgs }:

with pkgs; rustPlatform.buildRustPackage rec {
  pname = "rsop";
  version = "1.2.2";

  src = fetchFromGitHub {
    owner = "desbma";
    repo = pname;
    rev = "${version}";
    sha256 = "sha256-L4KzRAjDjprs/vwaJCp7tW3eGQxJ0H8Sv7v/LXkK4zo=";
  };

  cargoSha256 = "sha256-1CjU2XUBMYzj5OKqqlH0vm4dyWougwWiPZlQeSsxG5M=";
}

And resulted with errors below (probably raw cargo usage instead of nix would result in the same error).

error[E0433]: failed to resolve: use of undeclared crate or module `nix`
   --> src/handler.rs:108:9
    |
108 |         nix::unistd::sysconf(nix::unistd::SysconfVar::PAGE_SIZE).expect("Unable to get page size").unwrap() as usize;
    |         ^^^ use of undeclared crate or module `nix`

error[E0433]: failed to resolve: use of undeclared crate or module `nix`
   --> src/handler.rs:108:30
    |
108 |         nix::unistd::sysconf(nix::unistd::SysconfVar::PAGE_SIZE).expect("Unable to get page size").unwrap() as usize;
    |                              ^^^ use of undeclared crate or module `nix`

error[E0433]: failed to resolve: use of undeclared crate or module `nix`
   --> src/handler.rs:232:13
    |
232 |             nix::unistd::access(path, nix::unistd::AccessFlags::R_OK)
    |             ^^^ use of undeclared crate or module `nix`

error[E0433]: failed to resolve: use of undeclared crate or module `nix`
   --> src/handler.rs:232:39
    |
232 |             nix::unistd::access(path, nix::unistd::AccessFlags::R_OK)
    |                                       ^^^ use of undeclared crate or module `nix`

[ 50%] Building C object src/nvim/CMakeFiles/nvim.dir/auto/lua_api_c_bindings.generated.c.o
[ 50%] Building C object src/nvim/CMakeFiles/nvim.dir/api/buffer.c.o
[ 50%] Building C object src/nvim/CMakeFiles/nvim.dir/__/__/test/unit/fixtures/multiqueue.c.o
[ 50%] Building C object src/nvim/CMakeFiles/nvim.dir/__/__/cmake.config/auto/pathdef.c.o
[ 50%] Building C object src/nvim/CMakeFiles/nvim.dir/__/__/test/unit/fixtures/rbuffer.c.o
[ 50%] Building C object src/nvim/CMakeFiles/nvim.dir/main.c.o
[ 50%] Building C object src/nvim/CMakeFiles/nvim.dir/api/command.c.o
[ 50%] Building C object src/nvim/CMakeFiles/nvim.dir/api/extmark.c.o
[ 50%] Building C object src/nvim/CMakeFiles/nvim.dir/api/autocmd.c.o
[ 50%] Building C object src/nvim/CMakeFiles/nvim.dir/api/deprecated.c.o
error[E0277]: `MutexGuard<'_, BufReader<std::io::stdio::StdinRaw>>` cannot be sent between threads safely
   --> src/handler.rs:118:19
    |
118 | impl ReadPipe for StdinLock<'_> {}
    |                   ^^^^^^^^^^^^^ `MutexGuard<'_, BufReader<std::io::stdio::StdinRaw>>` cannot be sent between threads safely
    |
    = help: within `StdinLock<'_>`, the trait `Send` is not implemented for `MutexGuard<'_, BufReader<std::io::stdio::StdinRaw>>`
    = note: required because it appears within the type `StdinLock<'_>`
note: required by a bound in `ReadPipe`
   --> src/handler.rs:112:24
    |
112 | trait ReadPipe: Read + Send {}
    |                        ^^^^ required by this bound in `ReadPipe`

Some errors have detailed explanations: E0277, E0433.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `rsop` due to 5 previous errors
error: builder for '/nix/store/k16gqbl3q7825d96l2z8hsacshc6kxkr-rsop-1.2.2.drv' failed with exit code 101;
       last 10 log lines:
       >     = note: required because it appears within the type `StdinLock<'_>`
       > note: required by a bound in `ReadPipe`
       >    --> src/handler.rs:112:24
       >     |
       > 112 | trait ReadPipe: Read + Send {}
       >     |                        ^^^^ required by this bound in `ReadPipe`
       >
       > Some errors have detailed explanations: E0277, E0433.
       > For more information about an error, try `rustc --explain E0277`.
       > error: could not compile `rsop` due to 5 previous errors
       For full logs, run 'nix log /nix/store/k16gqbl3q7825d96l2z8hsacshc6kxkr-rsop-1.2.2.drv'.

Looking at https://github.com/desbma/rsop/blob/7ffa5a911b85121ed72b2d10bb7d065b0baa2212/Cargo.toml#L31-L32 gives a hint about requiring nix crate on linux and android seems to do with this build failure on darwin platform.

So I'm wondering about few things:


On a sidenote, I have been managing the branching which previewer binary to print contents when used with lf file manager with https://github.com/ryuheechul/dotfiles/blob/master/lf/pv.sh and just discovered rsop which looks way cooler than my short bash script so I hoping to give it a try!

desbma commented 1 year ago

is it designed to run only on linux?

It should work on most (all ?) Unixes, but because I only use Linux, and have never really tested building for other targets, it got broken.

if not what can help this build issue on darwin?

I have made some fixes to build for the x86_64-apple-darwin target in the macos branch. If you can build that code, and run it to check everything works fine that would help. If you can and have time to contribute code to update the Github actions, so that we build for Mac at each commit and can detect such breakages in the future, that would be even better.

ryuheechul commented 1 year ago

Hi @desbma, thanks for fixing that I just tested with the code below and it worked :)

# based on the example code from the link below
# https://github.com/NixOS/nixpkgs/blob/645bc49f34fa8eff95479f0345ff57e55b53437e/pkgs/tools/misc/hexyl/default.nix

# more info on rust + nix can be found at
# https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/rust.section.md
{ pkgs }:

with pkgs; rustPlatform.buildRustPackage rec {
  pname = "rsop";
  # version = "1.2.2";
  version = "macos";

  src = fetchFromGitHub {
    owner = "desbma";
    repo = pname;
    rev = "${version}";

    sha256 = "sha256-wy3QJqBd+8Kwkjm/IxtsVafESloOvDXF2D1YRVwGkz4=";
  };

  cargoSha256 = "sha256-hz/cR0WcLngMw4X+c4m7uv45ZrPH4PssR5lTp7W5yYc=";

  postInstall = ''
    ln -rs "$out"/bin/rs{op,o}
    ln -rs "$out"/bin/rs{op,e}
    ln -rs "$out"/bin/rs{op,p}
    ln -rs "$out"/bin/rs{op,i}
  '';
}

I also added the macOS in the CI, you can see the change here, https://github.com/desbma/rsop/compare/macos...ryuheechul:rsop:macos. And the result is here, https://github.com/ryuheechul/rsop/actions/runs/4774434134.

If you like it, I can file a PR with it. If so let me know which branch to target!

desbma commented 1 year ago

Thanks, you can make a PR targeting the macos branch.

I don't think the step to setup NodeJS is needed though.

ryuheechul commented 1 year ago

Sounds good and I just opened the PR. I added NodeJS steps because I saw some warning regarding NodeJS. However after your comment I checked again and still the warning so the change didn't improve anything on that therefore it's deleted :)

desbma commented 1 year ago

master branch now builds on MacOS