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

feat: Set darwin cflags fd_setsize and darwin_unlimited_select #480

Conversation

djgoku
Copy link

@djgoku djgoku commented Mar 15, 2025

I’m not sure if you’re open to this change. If not, we can close this PR.

I’ve been having issues with macOS when I have too many files open. I’ve been testing this for a few weeks, and I haven’t encountered any more errors from Emacs about too many files open.

Prior work

d12frosted/homebrew-emacs-plus@4b34ed7

Context

https://en.liujiacai.net/2022/09/03/emacs-maxopenfiles/

Copy link
Member

@jian-lin jian-lin left a comment

Choose a reason for hiding this comment

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

I will not comment on the specific added cflags because I do not know darwin.

To avoid duplication, you should add cflags here.

To support __structuredAttrs, those flags should be added like this:

env = old.env or { } // {
  CFLAGS = env.CFLAGS or "" + self.lib.optionalString self.stdenv.hostPlatform.isDarwin " -DFD_SETSIZE=10000 -DDARWIN_UNLIMITED_SELECT ";
}

Probably, CFLAGS should be changed to NIX_CFLAGS_COMPILE.

@djgoku djgoku force-pushed the feature/add-darwin-cflags-to-set-fd-setsize-and-darwin-unlimited-select branch from fc0a950 to 80cc298 Compare March 17, 2025 18:52
@djgoku
Copy link
Author

djgoku commented Mar 17, 2025

@jian-lin, thank you for your review and guidance.

I couldn’t get NIX_CFLAGS_COMPILE to work either with the same code or other examples I found. So, I stuck with CFLAGS.

Please let me know if there are any other changes that are needed.

@djgoku djgoku requested a review from jian-lin March 17, 2025 19:41
@jian-lin
Copy link
Member

jian-lin commented Mar 17, 2025

I couldn’t get NIX_CFLAGS_COMPILE to work either

What is the error when you try NIX_CFLAGS_COMPILE?

Ah, I had a typo in my previous code: env.CFLAGS should be old.env.CFLAGS.

I just tested the following code and it compiled fine.

              env = old.env or { } // {
                NIX_CFLAGS_COMPILE = (old.env.NIX_CFLAGS_COMPILE or "") +  self.lib.optionalString self.stdenv.hostPlatform.isDarwin " -DFD_SETSIZE=10000 -DDARWIN_UNLIMITED_SELECT ";
              };

Please use this code if it works.


This PR should be created in Nixpkgs instead of emacs-overlay and modify this code.


I searched github for nix code containing DARWIN_UNLIMITED_SELECT and only found 4 results. This makes me question the necessity of these flags.

@jian-lin jian-lin removed their request for review March 17, 2025 21:23
@djgoku
Copy link
Author

djgoku commented Mar 17, 2025

@jian-lin there were no errors I just didn't see CFLAGS apart of M-x emacs-build-description`.

I know this isn't nix but but it is specific to macOS only:

railwaycat/homebrew-emacsmacport#338

Let me see if there is a better way to test and show emacs behaving when these options are passed in or not passed in.

@jian-lin
Copy link
Member

I believe both NIX_CFLAGS_COMPILE and CFLAGS have the same effect. If you add NIX_DEBUG=4; inside overrideAttrs, you can see these two flags are passed to the compiler in build log.

NIX_CFLAGS_COMPILE is just a bit more idiomatic.

@djgoku djgoku force-pushed the feature/add-darwin-cflags-to-set-fd-setsize-and-darwin-unlimited-select branch from 80cc298 to d443751 Compare March 18, 2025 00:43
@djgoku
Copy link
Author

djgoku commented Mar 18, 2025

EDIT I switched to your nix code and it is working.

Only way I know to confirm is by running in emacs gu: (shell-command-to-string "ulimit -n") which returns 7168.

Only a build without NIX_CFLAGS_COMPILE (shell-command-to-string "ulimit -n") will return 1024.

One reason I would say use CFLAGS over NIX_CFLAGS_COMPILE is you can see the CFLAGS compiled in with M-x emacs-build-description:

CFLAGS:

In GNU Emacs 31.0.50 (build 1, aarch64-apple-darwin24.3.0, NS
appkit-2575.40 Version 15.3.2 (Build 24D81))
Repository revision: d708ebe401a2001e764821b7e43d9e9aaa23ea95
Repository branch: master
Windowing system distributor 'Apple', version 10.3.2575
System Description:  macOS 15.3.2

Configured using:
 'configure
 --prefix=/nix/store/9jqfifh63x5cwm5ahy8pfz09jjsl8a6j-emacs-git-pgtk-20250317.0
 --disable-build-details --with-modules --disable-ns-self-contained
 --with-ns --with-compress-install --with-toolkit-scroll-bars
 --with-native-compilation --without-imagemagick --with-mailutils
 --without-small-ja-dic --with-tree-sitter --without-xinput2
 --without-xwidgets --without-dbus --without-selinux 'CFLAGS=
 -DFD_SETSIZE=10000 -DDARWIN_UNLIMITED_SELECT ''

NIX_CFLAGS_COMPILE (no indication CFLAGS were changed):

In GNU Emacs 31.0.50 (build 1, aarch64-apple-darwin24.3.0, NS
appkit-2575.40 Version 15.3.2 (Build 24D81))
Repository revision: d708ebe401a2001e764821b7e43d9e9aaa23ea95
Repository branch: master
Windowing system distributor 'Apple', version 10.3.2575
System Description:  macOS 15.3.2

Configured using:
 'configure
 --prefix=/nix/store/iamdx0i38garf2rrc4dcbbzcz7lfr0ig-emacs-git-pgtk-20250317.0
 --disable-build-details --with-modules --disable-ns-self-contained
 --with-ns --with-compress-install --with-toolkit-scroll-bars
 --with-native-compilation --without-imagemagick --with-mailutils
 --without-small-ja-dic --with-tree-sitter --without-xinput2
 --without-xwidgets --without-dbus --without-selinux'

@jian-lin
Copy link
Member

jian-lin commented Mar 18, 2025

LGTM

As I said above, this change should go into Nixpkgs instead of emacs-overlay. Could you create a PR there? I am happy to merger it.

@djgoku
Copy link
Author

djgoku commented Mar 19, 2025

LGTM

As I said above, this change should go into Nixpkgs instead of emacs-overlay. Could you create a PR there? I am happy to merger it.

Thanks for the review. Hoping to have a pr to nixpkgs master today.

@djgoku
Copy link
Author

djgoku commented Mar 20, 2025

@jian-lin closing this since I have opened NixOS/nixpkgs#391407

@djgoku djgoku closed this Mar 20, 2025
@opsroller
Copy link

Great, so the sane people should go back to a completely custom overlay to remove this hack?

This screams of a severe local misconfiguration.

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.

3 participants