Skip to content

Commit

Permalink
fix(nix): use nix gcc and provide libiconv (#916)
Browse files Browse the repository at this point in the history
* fix(nix): use nix gcc and provide libiconv

Fixes iconv problems on darwin when using nix's gcc by removing
an impurity from build.

Adding this is apparently a no-op for linux, because libiconv is included by default in libc for linux.
This allows us to omit conditionals.

Before:
```sh
❯ otool -L libblink_cmp_fuzzy.dylib
libblink_cmp_fuzzy.dylib:
        /Users/konrad/Code/github.com/konradmalik/blink.cmp/target/release/deps/libblink_cmp_fuzzy.dylib (compatibility version 0.0.0, current version 0.0.0)
        /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1351.0.0)
```

After:
```sh
❯ otool -L ./target/release/libblink_cmp_fuzzy.dylib
./target/release/libblink_cmp_fuzzy.dylib:
        /Users/konrad/Code/github.com/konradmalik/blink.cmp/target/release/deps/libblink_cmp_fuzzy.dylib (compatibility version 0.0.0, current version 0.0.0)
        /nix/store/v7ldx1ra3wrjaasap8bfradapkqi2w1r-libiconv-107/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.0.0)
```

* ci(nix): check, build, run, even on prs

Also adds nix-comminity cache to avoid builds from fenix.
  • Loading branch information
konradmalik authored Jan 6, 2025
1 parent 7afccf8 commit 5d2d601
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 27 deletions.
21 changes: 0 additions & 21 deletions .github/workflows/nix-build.yaml

This file was deleted.

38 changes: 38 additions & 0 deletions .github/workflows/nix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Test Nix

on:
push:
pull_request:

jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
name: Test Nix Build on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@main
with:
extra-conf: |
accept-flake-config = true
- uses: DeterminateSystems/magic-nix-cache-action@main

- name: Check the flake
run: nix flake check

- name: Build devshell
run: nix develop --command "rustc"

- name: Build the library
run: nix build .#blink-fuzzy-lib

- name: Build the plugin in nix
run: nix build .#blink-cmp

- name: Build the library (outside nix)
run: nix run .#build-plugin
15 changes: 9 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,9 @@
program = let
buildScript = pkgs.writeShellApplication {
name = "build-plugin";
runtimeInputs = with pkgs;
[
fenix.minimal.toolchain
]
# use the native gcc on macos, see #652
++ lib.optionals (!pkgs.stdenv.isDarwin) [ gcc ];
runtimeInputs = with pkgs; [ fenix.minimal.toolchain gcc ];
text = ''
export LIBRARY_PATH="${lib.makeLibraryPath [ pkgs.libiconv ]}";
cargo build --release
'';
};
Expand All @@ -110,4 +106,11 @@
formatter = pkgs.nixfmt-classic;
};
};

nixConfig = {
extra-substituters = [ "https://nix-community.cachix.org" ];
extra-trusted-public-keys = [
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs"
];
};
}

0 comments on commit 5d2d601

Please sign in to comment.