Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not depend on system tools on Darwin #2136

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

avdv
Copy link
Member

@avdv avdv commented Mar 19, 2024

Our cc wrapper was always using the system tools from a fixed location on Darwin, which is not hermetic
(and can lead to problems when using nixpkgs) and requires the Xcode command line tools to be installed.

Apply the same heuristic as for the otool and install_name tool for the haskell toolchain and assume
the tools are available at the same location as the ar binary.

Depends on tweag/rules_nixpkgs#479 and depends on #2119

@avdv avdv force-pushed the darwin-dont-use-system-tools branch from 236ca50 to 237ecb7 Compare March 27, 2024 10:06
@avdv avdv mentioned this pull request Mar 27, 2024
4 tasks
@avdv avdv force-pushed the darwin-dont-use-system-tools branch from fba3fce to 9d5fd18 Compare April 2, 2024 13:08
@avdv
Copy link
Member Author

avdv commented Apr 30, 2024

@Mergifyio rebase

Copy link
Contributor

mergify bot commented Apr 30, 2024

rebase

✅ Branch has been successfully rebased

@avdv avdv force-pushed the darwin-dont-use-system-tools branch from 9d5fd18 to 22c032d Compare April 30, 2024 18:25
@avdv avdv force-pushed the darwin-dont-use-system-tools branch 2 times, most recently from dedc6cd to 42068b0 Compare May 14, 2024 08:26
@avdv avdv requested a review from ylecornec May 14, 2024 08:27
avdv added 2 commits May 14, 2024 10:31
Our cc wrapper was always using the system tools from a fixed location on Darwin, which is not hermetic
(and can lead to problems when using nixpkgs) and requires the Xcode command line tools to be installed.

Apply the same heuristic as for the otool and install_name tool for the haskell toolchain and assume
the tools are available at the same location as the `ar` binary.
... in case the `codesign` binary is not part of the directory where the `ar` tool
resides.

This might happen when not using a toolchain configured by nixpkgs_cc_configure,
but instead using one from a nix-shell. The codesign tool is not part of a
nixpkgs stdenv cc toolchain by default.
@avdv avdv force-pushed the darwin-dont-use-system-tools branch from 42068b0 to be50c26 Compare May 14, 2024 08:32
Copy link
Member

@ylecornec ylecornec left a comment

Choose a reason for hiding this comment

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

I left a few comments, but otherwise it looks good to me 👍

# Fall back to /usr/bin/codesign if the `CODESIGN` executable is not available
# (this might happen when using a default cc toolchain from a nix shell on Darwin instead
# of using a nixpkgs_cc_configure'd toolchain).
codesign = CODESIGN if os.access(CODESIGN, os.X_OK) else "/usr/bin/codesign"
Copy link
Member

Choose a reason for hiding this comment

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

Should we do similar checks for INSTALL_NAME_TOOL and OTOOL ?

# This is necessary on MacOS Monterey on M1.
# The moving back and forth is necessary because the OS caches the signature.
# See this note from nixpkgs for reference:
# https://github.com/NixOS/nixpkgs/blob/5855ff74f511423e3e2646248598b3ffff229223/pkgs/os-specific/darwin/signing-utils/utils.sh#L1-L6
os.rename(output, f"{output}.resign")
subprocess.check_call([CODESIGN] + ["-f", "-s", "-"] + [f"{output}.resign"])
subprocess.check_call([codesign] + ["-f", "-s", "-"] + [f"{output}.resign"], env = {'CODESIGN_ALLOCATE': CODESIGN_ALLOCATE})
Copy link
Member

Choose a reason for hiding this comment

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

Maybe if {:bindir:}/codesign is not available then we should not set the CODESIGN_ALLOCATE ? Since it also points to {:bindir}.

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.

None yet

2 participants