summaryrefslogtreecommitdiff
path: root/nonguix/build/chromium-binary-build-system.scm
blob: 0295891d6a633de35f230586871b7b8f428cf47d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
;;; SPDX-License-Identifier: GPL-3.0-or-later
;;; Copyright © 2023 Giacomo Leidi <goodoldpaul@autistici.org>

(define-module (nonguix build chromium-binary-build-system)
  #:use-module ((guix build gnu-build-system) #:prefix gnu:)
  #:use-module ((nonguix build binary-build-system) #:prefix binary:)
  #:use-module (guix build utils)
  #:use-module (ice-9 ftw)
  #:use-module (ice-9 match)
  #:export (%standard-phases
            chromium-binary-build))

;; Commentary:
;;
;; Builder-side code of the Chromium binary build procedure.
;;
;; Code:

(define* (install-wrapper #:key inputs outputs #:allow-other-keys)
  (let* ((output (assoc-ref outputs "out"))
         (bin (string-append output "/bin"))
         (fontconfig-minimal (assoc-ref inputs "fontconfig"))
         (nss (assoc-ref inputs "nss"))
         (wrap-inputs (map cdr inputs))
         (lib-directories
          (search-path-as-list '("lib") wrap-inputs))
         (bin-directories
          (search-path-as-list
           '("bin" "sbin" "libexec")
           wrap-inputs)))
    (for-each
     (lambda (exe)
       (display (string-append "Wrapping " exe "\n"))
       (wrap-program exe
         `("FONTCONFIG_PATH" ":" prefix
           (,(string-join
              (list
               (string-append fontconfig-minimal "/etc/fonts")
               output)
              ":")))
         `("PATH" ":" prefix
           (,(string-join
              (append
               bin-directories
               (list
                bin))
              ":")))
         `("LD_LIBRARY_PATH" ":" prefix
           (,(string-join
              (append
               lib-directories
               (list
                (string-append nss "/lib/nss")
                output))
              ":")))
         ;; Give a hint to Electron-based apps to detect if Wayland or X11 should
         ;; be used.
         ;; NOTE: The env-var version of this CLI arg was added in Electron >=28
         `("ELECTRON_OZONE_PLATFORM_HINT" ":" =
           ("auto"))))
     (map
      (lambda (exe) (string-append bin "/" exe))
      (filter
       (lambda (exe) (not (string-prefix? "." exe)))
       (scandir bin))))
    #t))

(define %standard-phases
  ;; Everything is as with the binary-build-system except for the
  ;; `install-wrapper' phase.
  (modify-phases binary:%standard-phases
    (add-after 'install 'install-wrapper install-wrapper)))

(define* (chromium-binary-build #:key inputs (phases %standard-phases)
                                #:allow-other-keys #:rest args)
  "Build the given package, applying all of PHASES in order."
  (apply gnu:gnu-build #:inputs inputs #:phases phases args))

;;; chromium-binary-build-system.scm ends here