aboutsummaryrefslogtreecommitdiff
path: root/gn/packages/virtualization.scm
blob: 9e7efd7469aede10d6c1e7111553fad3dc9dde7d (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
(define-module (gn packages virtualization)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix gexp)
  #:use-module (guix utils)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix git-download)
  #:use-module (guix build-system scons)
  #:use-module (gnu packages)
  #:use-module (gnu packages boost)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages cpp)
  #:use-module (gnu packages graphviz)
  #:use-module (gnu packages image)
  #:use-module (gnu packages m4)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages protobuf)
  #:use-module (gnu packages python)
  #:use-module (gnu packages python-xyz))

(define-public gem5
  (package
    (name "gem5")
    (version "21.2.1.0")
    (source
      (origin
        (method git-fetch)
        (uri (git-reference
               (url "https://gem5.googlesource.com/public/gem5")
               (commit (string-append "v" version))))
        (file-name (git-file-name name version))
        (sha256
         (base32 "0wyns8cfkigzw3m21331m8ydc7akm8l2lp0kci4pq8jyzsanmjm3"))
        (snippet
          #~(begin
              (use-modules (guix build utils))
              ;; For reproducibility.
              (substitute* "src/base/date.cc"
                (("__DATE__") "\"1970-01-01\"")
                (("__TIME__") "\"00:00:00\""))
              (substitute* "ext/sst/Makefile"
                (("-I../../ext/pybind11/include/")
                 "${shell pybind11-config --includes}"))
              (substitute* "SConstruct"
                ((".*pybind11.*") ""))
              (delete-file-recursively "ext/pybind11")))))
    (build-system scons-build-system)
    (arguments
     `(#:scons-flags
       (list "--verbose")
       #:build-targets '("build/ARM/gem5.opt"
                         "build/MIPS/gem5.opt"
                         "build/NULL/gem5.opt"
                         "build/POWER/gem5.opt"
                         "build/RISCV/gem5.opt"
                         "build/SPARC/gem5.opt"
                         "build/X86/gem5.opt")
       #:phases
       (modify-phases %standard-phases
         (add-after 'unpack 'patch-source
           (lambda* (#:key inputs #:allow-other-keys)
             (substitute* "SConstruct"
               ;; Scons does not use the environment variables by default,
               ;; but this substitution makes it do so.
               ;(("main = Environment")
               ; "main = Environment(ENV=os.environ)\nmain = Environment")
               ;; Force adding missing includes into the environment.
               (("main\\.Append\\(CPPPATH=\\[Dir\\('" all)
                (string-append
                  all (assoc-ref inputs "kernel-headers") "/include')])\n"
                  all (assoc-ref inputs "libpng") "/include')])\n"
                  all (assoc-ref inputs "pybind11") "/include')])\n"
                  all (assoc-ref inputs "zlib") "/include')])\n"
                  all)))
             (substitute* "ext/libelf/SConscript"
               (("m4env\\.Tool" all)
                (string-append
                  "m4env.Append(CPPPATH=[Dir('"
                  (assoc-ref inputs "kernel-headers")
                  "/include')])\n"
                  all)))
             (substitute* "ext/libelf/native-elf-format"
               (("cc") ,(cc-for-target)))))
         ;; This uses the cached results from the previous 'build phase.
         ;; Move to after 'install and delete build dir first?
         (replace 'check
           (lambda* (#:key tests? #:allow-other-keys #:rest args)
             (when tests?
               (apply (assoc-ref %standard-phases 'build)
                      #:build-targets '("build/NULL/unittests.opt")
                      args))))
         (replace 'install
           (lambda* (#:key outputs #:allow-other-keys)
             (let* ((out (assoc-ref outputs "out"))
                    (bin (string-append out "/bin/")))
               (mkdir-p bin)
               (for-each
                 (lambda (arch)
                   (when (directory-exists?
                           (string-append "build/" (string-upcase arch)))
                     (copy-file
                       (string-append "build/" (string-upcase arch) "/gem5.opt")
                       (string-append bin "gem5-" arch ".opt"))
                     (copy-file
                       (string-append "build/" (string-upcase arch) "/gem5py")
                       (string-append bin "gem5py-" arch))
                     (copy-file
                       (string-append "build/" (string-upcase arch) "/gem5py_m5")
                       (string-append bin "gem5py_m5-" arch))))
                 (list "arm" "mips" "null" "power" "riscv" "sparc" "x86")))))
         (add-after 'install 'install-configs
           (lambda* (#:key outputs #:allow-other-keys)
             (let* ((out  (assoc-ref outputs "out"))
                    (dest (string-append out "/share/gem5/configs")))
               (copy-recursively "configs" dest))))
         (add-after 'install 'wrap-binaries
           (lambda* (#:key outputs #:allow-other-keys)
             (let ((out (assoc-ref outputs "out")))
               (for-each
                 (lambda (file)
                   (wrap-program file
                     `("GUIX_PYTHONPATH" ":" prefix
                       (,(getenv "GUIX_PYTHONPATH")))))
                 (find-files (string-append out "/bin")))))))))
    (inputs
     (list gperftools
           libpng
           protobuf
           pybind11
           python
           python-pydot
           python-six
           zlib))
    (native-inputs
     (list boost
           m4
           pkg-config))
    (home-page "http://gem5.org/")
    (synopsis "Modular platform for computer-system architecture research")
    (description "The gem5 simulator is a modular platform for computer-system
architecture research, encompassing system-level architecture as well as
processor microarchitecture.")
    (license license:bsd-2)))

(define-public gem5-riscv
  (package
    (inherit gem5)
    (name "gem5-riscv")
    (arguments
     (substitute-keyword-arguments (package-arguments gem5)
       ((#:build-targets _ '())
        `(list "build/RISCV/gem5.opt"))
       ((#:phases phases)
        `(modify-phases ,phases
           (replace 'install
               (lambda* (#:key outputs #:allow-other-keys)
               (let* ((out (assoc-ref outputs "out"))
                      (bin (string-append out "/bin")))
                 (install-file "build/RISCV/gem5.opt" bin)
                 (install-file "build/RISCV/gem5py" bin)
                 (install-file "build/RISCV/gem5py_m5" bin))))))))))