diff --git a/config-programming.org b/config-programming.org index 7a172a7..3bf86c2 100644 --- a/config-programming.org +++ b/config-programming.org @@ -59,9 +59,11 @@ :hook (lsp-completion-mode . my/lsp-mode-setup-completion) :config + (require 'my-nprocs) (with-eval-after-load 'lsp-clangd (add-to-list 'lsp-clients-clangd-args - "-j=16")) + (format "-j=%d" + (nprocs)))) (setq lsp-clangd-binary-path (executable-find "clangd")) diff --git a/lisp/llvm-lib/llvm-shared.el b/lisp/llvm-lib/llvm-shared.el index 64454b4..ff731ca 100644 --- a/lisp/llvm-lib/llvm-shared.el +++ b/lisp/llvm-lib/llvm-shared.el @@ -28,14 +28,12 @@ (require 'eieio) (require 'load-llvm-mode) (require 'my-clang-options) +(require 'my-nprocs) ;; =========================== LLVM Rebuild ========================== (defvar llvm-core-count - (--> "nproc" - (shell-command-to-string it) - (string-to-number it) - (- it 16))) + (nprocs)) (defun lls/ninja-build-tools (build-dir tools-list &optional verbose) (format "set -o pipefail && CLICOLOR_FORCE=1 ninja -C %s -j %d %s %s 2>&1 | tee ninja.log" diff --git a/lisp/my-nprocs.el b/lisp/my-nprocs.el new file mode 100644 index 0000000..d647e51 --- /dev/null +++ b/lisp/my-nprocs.el @@ -0,0 +1,41 @@ +;;; my-nprocs.el --- -*- lexical-binding: t -*- + +;; Copyright (C) 2024 Benson Chu + +;; Author: Benson Chu +;; Created: [2024-12-27 10:07] + +;; This file is not part of GNU Emacs + +;; This program is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;;; Code: +(require 'dash) + +(defvar nprocs-cache nil) + +(defun nprocs () + (or nprocs-cache + (setq nprocs-cache + (--> + (shell-command-to-string "nproc") + (string-to-number it) + (let ((num it)) + (max (- num 16) + (/ num 2))))))) + +(provide 'my-nprocs) +;;; my-nprocs.el ends here