Skip to content

Conversation

@josibake
Copy link
Contributor

@josibake josibake commented Jun 24, 2025

Add a depends devshell. This shell only includes packages needed for doing a depends build and some basic debugging tools.

This needs to be a separate shell because depends building will fail if there are system packages installed. Conceptually, its also cleaner to only include the necessary dependencies for a depends build since this is precisely the scenario in which depends is useful.

Closes #19

@josibake
Copy link
Contributor Author

Note: will need to also update the CI depends job once this merges to use the new shell, but I didn't want to mix CI changes in this one and in theory this new one shouldn't break the old one.

Copy link
Contributor

@willcl-ark willcl-ark left a comment

Choose a reason for hiding this comment

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

This shim is pretty neat conceptually, but personally I'd make it a bit more "nixxy", like this:

diff --git a/flake.nix b/flake.nix
index 7201ec9..8c5a88a 100644
--- a/flake.nix
+++ b/flake.nix
@@ -55,6 +55,20 @@
           linuxPackages.bpftrace
         ];
 
+      # Alias gcc/g++ to clang/clang++
+      clangShim = pkgs.stdenv.mkDerivation {
+        name = "clang-shim";
+        buildInputs = [llvmTools.clang];
+        phases = ["installPhase"];
+        installPhase = ''
+          mkdir -p $out/bin
+          ln -s ${llvmTools.clang}/bin/clang $out/bin/gcc
+          ln -s ${llvmTools.clang}/bin/clang++ $out/bin/g++
+          ln -s ${llvmTools.clang}/bin/clang $out/bin/clang
+          ln -s ${llvmTools.clang}/bin/clang++ $out/bin/clang++
+        '';
+      };
+
       # Will only exist in the build environment and includes everything needed
       # for a depends build
       dependsNativeBuildInputs = with pkgs;
@@ -64,8 +78,8 @@
           cmake
           curlMinimal
           llvmTools.bintools
-          llvmTools.clang
           llvmTools.clang-tools
+          clangShim
           ninja
           pkg-config
           xz
@@ -112,9 +126,6 @@
 
           inherit (env) CMAKE_GENERATOR LD_LIBRARY_PATH LOCALE_ARCHIVE;
         };
-        # TODO: this could be ported to a gcc shell in the future to bring this closer in line
-        # with our guix depends build. This would allow us to remove the shellHook hack that shims
-        # in clang to masquerade as gcc
         depends = pkgs.mkShellNoCC {
           nativeBuildInputs = dependsNativeBuildInputs;
           buildInputs = usdtPkgs;
@@ -123,19 +134,7 @@
             # build system, so we unset this in the depends devshell
             unset SOURCE_DATE_EPOCH
 
-            # its not super easy to override compiler defaults in
-            # depends, so as a hack we just shim in clang and pretend
-            # its gcc. this is done in a tmp dir to avoid polluting the
-            # users shell and is cleaned up when the shell is exited.
-            TMP_GCC_SHIM=$(mktemp -d "$TMPDIR/clang-shim.XXXXXX")
-
-            ln -sf $(command -v clang++) "$TMP_GCC_SHIM/g++"
-            ln -sf $(command -v clang) "$TMP_GCC_SHIM/gcc"
-
-            export PATH="$TMP_GCC_SHIM:$PATH"
-            echo "Using fake gcc/g++ -> clang in: $TMP_GCC_SHIM"
-
-            trap "rm -rf $TMP_GCC_SHIM" EXIT
+            echo "gcc/g++ are shimmed to llvm tools"
           '';
           inherit (env) CMAKE_GENERATOR LOCALE_ARCHIVE;
         };

LMK what you think?

@willcl-ark
Copy link
Contributor

Did a CI run using the shell in https://github.com/bitcoin-dev-tools/bix/actions/runs/15854794287/job/44697246541?pr=33

Feel free to cherry-pick that commit here if you like

@josibake
Copy link
Contributor Author

Thanks for the review, @willcl-ark , will update tomorrow! I much prefer your clangShim approach, will go with that instead. Alternatively, since we have separate devshells, maybe we just make the devShell.depends use the same gcc stdenv as our current depends build? That would at least make this dev environment one step close to mirroring our guix depends builds.

Also fine to go with this one for now and we can work on squaring up with guix builds as a separate task.

@willcl-ark
Copy link
Contributor

Well in my testing the shim seemed to break nixpkgs builds: https://github.com/bitcoin-dev-tools/bix/actions/runs/15859413754/job/44712638536?pr=33

but depends build worked ok: https://github.com/bitcoin-dev-tools/bix/actions/runs/15859413749/job/44712638535?pr=33

Not sure what happened. I can perhaps look more closely later, but just a heads-up

Add a depends devshell. This shell only includes packages needed for
doing a depends build and some basic debugging tools.

This needs to be a separate shell because depends building will fail
if there are system packages installed. Conceptually, its also cleaner
to only include the necessary dependencies for a depends build since
this is precisely the scenario in which depends is useful.
@josibake josibake force-pushed the add-depends-only-devshell branch from 2339ee4 to 92dedcf Compare June 26, 2025 12:27
@josibake
Copy link
Contributor Author

Updated to use clangShim. It wasn't clear to me what was going on with the CI failure you linked, so if the CI here fails I'll dig in and try to determine whats going on.

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.

Fix Qt compatibility

3 participants