[Replicant] [libsamsung-ril] [PATCH 04/23] Add guix.scm

Denis 'GNUtoo' Carikli GNUtoo at cyberdimension.org
Thu Mar 4 12:42:31 UTC 2021


Libsamsung-ipc that also has a guix.scm file to build
libsamsung-ipc in many different ways (with GCC, clang, from
the Android.mk, Autotools and with different build flags),
but it's not suited for libsamsung-ril as we just need one build
configuration of libsamsung-ipc from the master branch and not
from libsamsung-ipc currently checked out git tree.

So it's best to have a base libsamsung-ipc package in guix and
in libsamsung-ipc's guix.scm, inherit it to create all the
packages variants, and in libsamsung-ril to use the Guix'
libsamsung-ipc as a dependency, possibly using master as the
only modification.

If Guix can accept a package that uses the master branch with
potentially a floating revision that could be great, but as I
understand they at least discourage it. It's also unclear if
they would accept it if it's not generally useful (yet) as
it still requires vendor kernels at the time of writing.

If we probably need the following to be done before we can merge
this patch in libsamsung-ril to make libsamsung-ipc more generally
useful and be able to add it to Guix:
- Cleanup the Linux GT-I9300 modem driver, upstream it it
  possible or at least package it as an external module with DKMS.
- Add support for that module in the master branch of libsamsung-ipc
  (so with clean code and so on).
- Finish passing the ipc_client struct to all the functions in
  libsamsung-ipc and do all pending changes that break the
  API / ABI
- Make a new release of libsamsung-ipc.
- Include the new libsamsung-ipc release in Guix.
- (In parallel convert libsamsung-ipc guix.scm to use it).
- Convert this guix.scm to use the Guix' libsamsung-ipc.
- Finally merge this guix.scm in libsamsung-ril.

Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo at cyberdimension.org>
---
 scripts/guix.scm | 325 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 325 insertions(+)
 create mode 100644 scripts/guix.scm

diff --git a/scripts/guix.scm b/scripts/guix.scm
new file mode 100644
index 0000000..04a79a4
--- /dev/null
+++ b/scripts/guix.scm
@@ -0,0 +1,325 @@
+;;; Copyright © 2020 Denis Carikli <GNUtoo at cyberdimension.org>
+;;;
+;;; This file 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 file 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 GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+;;; The guix.scm file is a convention: A file named guix.scm is
+;;; found in several project source code, either in the top
+;;; directory or in sub-directories like contrib for instance.
+
+;;; The guix.scm files typically contain package definitions that
+;;; are not meant to be used as regular packages but are meant for
+;;; testing or developing on the given project.
+;;;
+;;; Here it enables to build libsamsung-ril under GNU/Linux from the
+;;; files currently present in this repository: Guix first copies all
+;;; the files in this repository as-is and builds them. So if there
+;;; are some local changes that aren't even committed in git yet, they
+;;; will also be picked up and built by Guix. This is very useful to
+;;; do fast compilation tests.
+;;;
+;;; Because of that it's also not adapted to be used as a regular package
+;;; as distributions would typically need to use a given git revision or
+;;; released tarballs instead of potentially locally modified code.
+;;;
+;;; Once you have Guix installed, to build libsamsung-ril with this
+;;; guix.scm file, you can use the 'guix build --file=scripts/guix.scm'
+;;; command.
+
+(use-modules
+ (ice-9 popen)
+ (ice-9 rdelim)
+ (sxml ssax input-parse)
+ ((guix licenses) #:prefix license:)
+ (guix build-system android-ndk)
+ (guix build-system gnu)
+ (guix gexp)
+ (guix git-download)
+ (guix packages)
+ (guix transformations)
+ (gnu packages)
+ (gnu packages android)
+ (gnu packages autotools)
+ (gnu packages disk)
+ (gnu packages linux)
+ (gnu packages llvm)
+ (gnu packages pkg-config)
+ (gnu packages python)
+ (gnu packages python-xyz)
+ (gnu packages tls))
+
+(define %strict-cflags "CFLAGS=-Werror -W -Wall -Wunused -Wunused-function")
+
+(define %libsamsung-ril-commit
+  (let* ((port (open-input-pipe
+                "git --no-pager log --oneline HEAD -1 --format='%H'"))
+         (str  (read-line port)))
+    (close-pipe port)
+    str))
+
+(define %local-source
+  (local-file
+   (dirname (dirname (current-filename)))
+   #:recursive? #t))
+
+;; We just need libsamsung-ipc to build libsamsung-ril.
+;; Using the Android.mk instead of Autotools can help spot more issues.
+;; For instance if libsamsung-ril depends on libsamsung-ipc code that is only
+;; built by the Autotools, using the Android.mk might spot that.
+;; Forgetting to update the Android.mk seems more frequent than forgetting
+;; to update the Autotools, because the code is often build tested with the
+;; Autotools while writing it.
+(define-public libsamsung-ipc
+  (package
+   (name "libsamsung-ipc")
+   ;; Note that the hash is ignored here because we use transformations
+   ;; to get the latest git version
+   (version (git-version "0.0" "HEAD"
+                         "73b26ca046c7dc2a3de89079203159a0cae83807"))
+   (source
+    (origin
+     (method git-fetch)
+     (uri
+      (git-reference
+       (url
+        "https://git.replicant.us/replicant/hardware_replicant_libsamsung-ipc")
+       ;; Note that the hashes are ignored here because we use transformations
+       ;; to get the latest git version
+       (commit "73b26ca046c7dc2a3de89079203159a0cae83807")))
+     (sha256 (base32 "0icrc6b8hsjvzr6wjhvylq8fkn9s8snm6qf6yvz0lnlnxv0xifgp"))
+     ))
+   (build-system android-ndk-build-system)
+   (inputs
+    `(("android-libutils" ,android-libutils)
+      ("libcrypto" ,openssl)))
+   (arguments
+    `(#:phases
+      (modify-phases
+       %standard-phases
+       (delete 'bootstrap)
+       (add-before
+        'build 'patch-host
+        (lambda _
+          (substitute* "Android.mk"
+                       (("BUILD_SHARED_LIBRARY") "BUILD_HOST_SHARED_LIBRARY")
+                       (("BUILD_STATIC_LIBRARY") "BUILD_HOST_STATIC_LIBRARY")
+                       (("BUILD_STATIC_EXECUTABLE")
+                        "BUILD_HOST_STATIC_EXECUTABLE"))
+          #t)))
+      #:make-flags (list ,%strict-cflags)))
+   (synopsis
+    "libsamsung-ipc is a free software implementation of the Samsung IPC modem
+ protocol")
+   (description
+    "libsamsung-ipc is a free software implementation of the Samsung IPC modem
+ protocol, found in many Samsung smartphones and tablets.")
+   (home-page "https://www.replicant.us")
+   (license license:gpl2+)))
+
+(define-public replicant-6-hardware_ril-headers
+  (package
+   (name "replicant-6-hardware_ril-headers")
+   (version "6.0-0003")
+   (source
+    (origin
+     (method git-fetch)
+     (uri
+      (git-reference
+       (url
+        "https://git.replicant.us/mirrors/LineageOS/android_hardware_ril.git")
+       (commit "f29d36b6b5430d3974b1857f8438d924c2f16a86")))
+     (file-name (git-file-name name version))
+     (sha256 (base32 "1inaz3lyqx3bmn6421yvxpkyj0v8vkslpl8ymxng2s3jm5xwi39g"))))
+   (build-system android-ndk-build-system)
+   (arguments
+    `(#:phases
+      (modify-phases
+       %standard-phases
+       (delete 'bootstrap)
+       (delete 'configure)
+       ;; We only want to packages the headers for now
+       (replace 'install
+                (lambda* (#:key outputs #:allow-other-keys)
+                         (let* ((out (assoc-ref outputs "out"))
+                                (include (string-append out "/include")))
+                           (copy-recursively
+                            "include" (string-append out "/include"))
+                           #t))))))
+   (synopsis "Headers of the RIL used by Replicant 6.0")
+   (description
+    "Headers of the The Radio Interface Layer (RIL) used by Replicant 6.0
+ The Radio Interface Layer (RIL) daemon is used to abstracts the modem
+ protocols in Android. It typically loads a libril counterpart that actually
+ implement a specific modem protocol, while the RIL daemon itself handles the
+ interface with the Android framework")
+   (home-page "https://www.replicant.us")
+   (license license:asl2.0)))
+
+(define-public replicant-6-libhardware_legacy
+  (package
+   (name "replicant-6-libhardware_legacy")
+   (version "6.0-0003")
+   (source
+    (origin
+     (method git-fetch)
+     (uri
+      (git-reference
+       (url
+        "https://git.replicant.us/replicant/hardware_libhardware_legacy.git")
+       (commit "0a29b8547b892115003c46ae17eae4b609aa9a87")))
+     (file-name (git-file-name name version))
+     (sha256 (base32 "1m8ip09pqw9gjrcqvsj3c7l2mxpaprp3z92sqq7qvp018ayqg1nv"))))
+   (build-system android-ndk-build-system)
+   (inputs
+    `(("android-libcutils" ,android-libcutils)
+      ("android-liblog" ,android-liblog)
+      ("libnl" ,libnl)))
+   (native-inputs
+    `(("android-core" ,(android-platform-system-core
+                        (android-platform-version)))))
+   (arguments
+    `(#:make-flags
+      (list
+       (string-append "CFLAGS= "
+                      ;; TODO: see the comment below about
+                      ;; unpacking android-core tarball.
+                      ;; Uncomment the following lines and
+                      ;; remove -I ../core/include when
+                      ;; this is fixed:
+                      ;; "-I " (assoc-ref %build-inputs "android-core")
+                      ;; "/include "
+                      "-I core/include "))
+      #:phases
+      (modify-phases
+       %standard-phases
+       ;; TODO: Guix's android.scm does that too in android-ext4-utils however
+       ;; it might be a good idea to instead package the android-code source
+       ;; code as-is instead of just downloading it as a tarball
+       (add-after
+        'unpack 'unpack-core
+        (lambda* (#:key inputs #:allow-other-keys)
+                 (mkdir-p "core")
+                 (with-directory-excursion
+                  "core"
+                  (invoke "tar" "axf" (assoc-ref inputs "android-core")
+                          "--strip-components=1"))
+                 #t))
+       (delete 'bootstrap)
+       (add-before
+        'build 'patch-host
+        (lambda _
+          ;; TODO: Cross-compile.
+          (substitute* "Android.mk"
+                       (("BUILD_SHARED_LIBRARY") "BUILD_HOST_SHARED_LIBRARY")
+                       (("BUILD_STATIC_LIBRARY") "BUILD_HOST_STATIC_LIBRARY")
+                       (("BUILD_STATIC_EXECUTABLE")
+                        "BUILD_HOST_STATIC_EXECUTABLE"))
+          #t)))))
+   (synopsis
+    "replicant-6-libhardware_legacy is Replicant 6.0's fork of Android's legacy
+ HAL (Hardware Abstraction Layer)")
+   (description
+    "replicant-6-libhardware_legacy is Replicant 6.0's fork of Android's legacy
+ HAL (Hardware Abstraction Layer).
+ At the beginning of Android, breaking the kernel API to support (new) hardware
+ faster was a common practice. This was handled by the use of an hardware
+ abstraction in userspace between the (highly modified) Linux kernel and the
+ Android framework that the Android applications interact with. In addition that
+ abstraction layer also supported userspace drivers for things that are not
+ typically handled by the kernel like modem or GPS protocols.")
+   (home-page "https://www.replicant.us")
+   (license license:asl2.0)))
+
+(define-public libsamsung-ril
+  (package
+   (name "libsamsung-ril")
+   (version (git-version "0.0" "HEAD" %libsamsung-ril-commit))
+   (source %local-source)
+   (build-system android-ndk-build-system)
+   (inputs
+    `(("android-libcutils" ,android-libcutils)
+      ("android-liblog" ,android-liblog)
+      ("android-libutils" ,android-libutils)
+      ("clang" ,clang)
+      ("libcrypto" ,openssl)
+      ("libsamsung-ipc" ,libsamsung-ipc)
+      ("replicant-6-libhardware_legacy" ,replicant-6-libhardware_legacy)))
+   (native-inputs
+    `(("android-core" ,(android-platform-system-core
+                        (android-platform-version)))
+      ("replicant-6-hardware_ril-headers" ,replicant-6-hardware_ril-headers)))
+   (arguments
+    `(#:make-flags
+      (list
+       (string-append
+        "CFLAGS=-W -Wall -Wno-unused "
+        "-DANDROID "
+        "-I core/include "
+        "-I " (assoc-ref %build-inputs "libsamsung-ipc")
+        "/include/samsung-ipc "
+        "-I " (assoc-ref %build-inputs "replicant-6-libhardware_legacy")
+        "/include "
+        "-I " (assoc-ref %build-inputs "replicant-6-hardware_ril-headers")
+        "/include ")
+       ;; We need to pass it LOCAL_MODULE=libsamsung-ril, else it only builds
+       ;; the libsrs-client target (and not the libsamsung-ril target nor any of
+       ;; the other tools).
+       ;; TODO: Build all the tools as well
+       "LOCAL_MODULE=libsamsung-ril")
+      #:phases (modify-phases
+                %standard-phases
+                (add-after
+                 'unpack 'unpack-core
+                 (lambda*
+                  (#:key inputs #:allow-other-keys)
+                  (mkdir-p "core")
+                  (with-directory-excursion
+                   "core"
+                   (invoke "tar" "axf" (assoc-ref inputs "android-core")
+                           "--strip-components=1"))
+                  #t))
+                (delete 'bootstrap)
+                (add-before
+                 'build 'patch-host
+                 (lambda _
+                   ;; TODO: Cross-compile.
+                   (substitute*
+                    "Android.mk"
+                    (("BUILD_SHARED_LIBRARY") "BUILD_HOST_SHARED_LIBRARY")
+                    (("BUILD_STATIC_LIBRARY") "BUILD_HOST_STATIC_LIBRARY")
+                    (("BUILD_STATIC_EXECUTABLE")
+                     "BUILD_HOST_STATIC_EXECUTABLE"))
+                   #t))
+                (add-after
+                 'patch-host
+                 'prepare-build-environment
+                 (lambda* (#:key inputs #:allow-other-keys)
+                          (setenv "CC" "clang")
+                          #t)))))
+   (synopsis
+    "libsamsung-ril is RIL library that uses libsamsung-ipc to implementation
+ the Samsung IPC modem protocol")
+   (description
+    "The Radio Interface Layer (RIL) daemon is used to abstracts the modem
+ protocols in Android. It typically loads a libril counterpart that actually
+ implement a specific modem protocol, while the RIL daemon itself handles the
+ interface with the Android framework. libsamsung-ril is libril library
+ that uses libsamsung-ipc to implementation the Samsung IPC modem protocol,
+ found in many Samsung smartphones and tablets.")
+   (home-page "https://www.replicant.us")
+   (license license:gpl2+)))
+
+(define use-libsamsung-ipc-master
+  (options->transformation
+   '((with-branch . "libsamsung-ipc=master"))))
+
+(list (use-libsamsung-ipc-master libsamsung-ril))
-- 
2.30.1



More information about the Replicant mailing list