Skip to content

Commit

Permalink
removeReferencesToVendoredSources: sign aarch64-darwin binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Zlender committed Oct 15, 2023
1 parent 4dcf584 commit e8d95d9
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
at build time. ([#407](https://github.com/ipetkov/crane/pull/407))
* Fixed handling of dummy target names to avoid issues with `cargo doc`.
([#410](https://github.com/ipetkov/crane/pull/410))
* `removeReferencesToVendoredSources` now signs `aarch64-darwin` binaries. ([#418](https://github.com/ipetkov/crane/pull/418))

## [0.14.1] - 2023-09-23

Expand Down
143 changes: 143 additions & 0 deletions checks/codesign/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions checks/codesign/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "codesign"
version = "0.1.0"
edition = "2021"

[profile.release]
debug = true

[dependencies]
openssl = "*"
3 changes: 3 additions & 0 deletions checks/codesign/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
openssl::ssl::SslConnector::builder(openssl::ssl::SslMethod::tls()).unwrap();
}
15 changes: 15 additions & 0 deletions checks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let
extensions = [ "llvm-tools" ];
});
x64Linux = pkgs.hostPlatform.system == "x86_64-linux";
aarch64Darwin = pkgs.hostPlatform.system == "aarch64-darwin";
in
{
cleanCargoTomlTests = callPackage ./cleanCargoTomlTests { };
Expand Down Expand Up @@ -107,6 +108,20 @@ in
};
});

# https://github.com/ipetkov/crane/issues/417
codesign = lib.optionalAttrs aarch64Darwin (
let
codesignPackage = myLib.buildPackage {
src = ./codesign;
cargoArtifacts = null;
nativeBuildInputs = [ pkgs.pkg-config pkgs.libiconv ];
buildInputs = [ pkgs.openssl ];
dontStrip = true;
};
in
pkgs.runCommand "codesign" { } "${codesignPackage}/bin/codesign > $out"
);

compilesFresh = callPackage ./compilesFresh.nix { };
compilesFreshSimple = self.compilesFresh "simple" (myLib.cargoBuild) {
src = ./simple;
Expand Down
2 changes: 2 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,8 @@ sources themselves. It takes two positional arguments:
* Note: it is expected that this directory has the exact structure as would
be produced by `craneLib.vendorCargoDeps`

Any patched binaries on `aarch64-darwin` will be [signed](https://developer.apple.com/library/archive/documentation/Security/Conceptual/CodeSigningGuide/Introduction/Introduction.html). You can disable this functionality by setting `doNotSign`.

**Automatic behavior:** if `cargoVendorDir` is set and
`doNotRemoveReferencesToVendorDir` is not set, then
`removeReferencesToVendoredSources "$out" "$cargoVendorDir"` will be run as a
Expand Down
10 changes: 9 additions & 1 deletion lib/setupHooks/removeReferencesToVendoredSources.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
{ makeSetupHook
{ darwin
, lib
, makeSetupHook
, stdenv
}:

let
darwinCodeSign = stdenv.targetPlatform.isDarwin && stdenv.targetPlatform.isAarch64;
in
makeSetupHook
{
name = "removeReferencesToVendoredSourcesHook";
substitutions = {
storeDir = builtins.storeDir;
sourceSigningUtils = if darwinCodeSign then "source ${darwin.signingUtils}" else null;
signIfRequired = if darwinCodeSign then ''if [ -z "''${doNotSign-}" ]; then signIfRequired "''${installedFile}"; fi'' else null;
};
} ./removeReferencesToVendoredSourcesHook.sh
4 changes: 4 additions & 0 deletions lib/setupHooks/removeReferencesToVendoredSourcesHook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ removeReferencesToVendoredSources() {
echo -n '\)!@storeDir@/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee!g'
)

@signIfRequired@
done < <(find "${installLocation}" -type f)
}

@sourceSigningUtils@

if [ -n "${doNotRemoveReferencesToVendorDir-}" ]; then
echo "removeReferencesToVendoredSources disabled"
elif [ -n "${cargoVendorDir-}" ]; then
Expand Down

0 comments on commit e8d95d9

Please sign in to comment.