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

Merged
merged 3 commits into from
Jul 2, 2024
Merged

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 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 ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think these tools really should be available from the same place as the ar tool. Otherwise mixing tools from different toolchains is just calling for trouble (as we've seen previously: tweag/rules_nixpkgs#479).

Also, the difference between the codesign and any of these tools from /usr/bin is that codesign does not need an installation of the Xcode command line tools, the latter do.

So I'd like to only do the fallback for codesign until there is a real problem that we need to solve.

# 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}.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we need to set CODESIGN_ALLOCATE for codesign to work. But I applied the same fallback for codesign_allocate now. It also does not need a Xcode installation and should work in tandem with codesign.

avdv added 3 commits July 2, 2024 17:56
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 be50c26 to ac40163 Compare July 2, 2024 15:56
@avdv avdv added the merge-queue merge on green CI label Jul 2, 2024
@mergify mergify bot merged commit ff807d9 into master Jul 2, 2024
93 of 116 checks passed
@mergify mergify bot deleted the darwin-dont-use-system-tools branch July 2, 2024 20:26
@mergify mergify bot removed the merge-queue merge on green CI label Jul 2, 2024
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.

2 participants