]> git.bitcoin.ninja Git - ldk-c-bindings/commitdiff
Don't pass 'embed-bitcode'/'lto' while building proc-macros
authorMatt Corallo <git@bluematt.me>
Tue, 4 Jun 2024 22:06:42 +0000 (22:06 +0000)
committerMatt Corallo <git@bluematt.me>
Thu, 6 Jun 2024 13:45:28 +0000 (13:45 +0000)
cargo is usually good about not passing `RUSTFLAGS` to build-time
dependencies which need to be built for the host platform rather
than the target platform, but for some reason it does not do so
for `proc-macro` crates.

Thus, we have to manually drop the `embed-bitcode` and `lto`
arguments when calling rustc in our existing rustc wrapper.

deterministic-build-wrappers/rustc

index b05d3407a9f14c39cad0f6a1a26104d49c97a46e..7acc9c4ccebb2f53b4bd2c76ae102fd7c3361533 100755 (executable)
@@ -7,13 +7,21 @@
 # ever (indirectly) depend on multiple versions of the same crate.
 args=("$@")
 IS_LIGHTNING=false
+SKIP_EMBED_BITCODE=false
 for ((i=0; i<"${#args[@]}"; ++i)); do
     case ${args[i]} in
         --crate-name)
-                       if [ "${args[i+1]}" = "lightning" -o "${args[i+1]}" = "lightning_background_processor" -o "${args[i+1]}" = "lightning_invoice" -o "${args[i+1]}" = "lightning_persister" -o "${args[i+1]}" = "lightning_rapid_gossip_sync" -o "${args[i+1]}" = "ldk" ]; then
+                       if [ "${args[i+1]}" = "lightning" -o "${args[i+1]}" = "lightning_background_processor" -o "${args[i+1]}" = "lightning_invoice" -o "${args[i+1]}" = "lightning_persister" -o "${args[i+1]}" = "lightning_rapid_gossip_sync" -o "${args[i+1]}" = "lightning_transaction_sync" -o "${args[i+1]}" = "ldk" ]; then
                                IS_LIGHTNING=true
                        fi
                        ;;
+               --crate-type)
+                       if [ "${args[i+1]}" = "proc-macro" ]; then
+                               # If we're building a proc-macro, rustc incorrectly passes our RUSTFLAGS containing
+                               # embed-bitcode=yes, which we don't want.
+                               SKIP_EMBED_BITCODE=true
+                       fi
+                       ;;
     esac
 done
 for ((i=0; i<"${#args[@]}"; ++i)); do
@@ -24,7 +32,16 @@ for ((i=0; i<"${#args[@]}"; ++i)); do
                                args[i]="metadata=42"
                        fi
                        ;;
+               embed-bitcode=yes)
+                       if [ "$SKIP_EMBED_BITCODE" = "true" ]; then
+                               args[i]="embed-bitcode=no"
+                       fi
+                       ;;
+               lto)
+                       if [ "$SKIP_EMBED_BITCODE" = "true" ]; then
+                               args[i]="lto=no"
+                       fi
+                       ;;
     esac
 done
-
 $LDK_RUSTC_PATH "${args[@]}"