Created
May 26, 2021 16:14
-
-
Save l04m33/cc31cac96437ff980f14f96882290a6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define-module (guix-local-packages zig) | |
#:use-module (guix packages) | |
#:use-module (guix download) | |
#:use-module (guix git-download) | |
#:use-module (guix build-system cmake) | |
#:use-module (guix build-system trivial) | |
#:use-module ((guix licenses) #:prefix license:) | |
#:use-module (gnu packages) | |
#:use-module (gnu packages python) | |
#:use-module (gnu packages compression) | |
#:export (zig | |
llvm-for-zig | |
zls)) | |
(define llvm-for-zig | |
(package | |
(name "llvm-for-zig") | |
(version "12.0.0") | |
(source (origin | |
(method git-fetch) | |
(uri (git-reference | |
(url "https://github.com/llvm/llvm-project.git") | |
(commit "llvmorg-12.0.0"))) | |
(sha256 | |
(base32 | |
"07jz8pywc2qqa1srdnqg5p2y4lx3ki1inpigarzgxc3j20r4gb58")))) | |
(build-system cmake-build-system) | |
(arguments `(#:build-type "Release" | |
#:tests? #f | |
#:modules ((srfi srfi-1) | |
(ice-9 match) | |
,@%cmake-build-system-modules) | |
#:phases | |
(modify-phases %standard-phases | |
;; Ripped from (gnu packages llvm). See `guix edit clang-runtime` | |
;; Work around https://issues.guix.info/issue/36882. We need to | |
;; remove glibc from CPLUS_INCLUDE_PATH so that the one hardcoded | |
;; in GCC, at the bottom of GCC include search-path is used. | |
(add-after 'set-paths 'hide-glibc | |
(lambda* (#:key inputs #:allow-other-keys) | |
(let* ((filters '("libc")) | |
(input-directories | |
(filter-map (lambda (input) | |
(match input | |
((name . dir) | |
(and (not (member name filters)) | |
dir)))) | |
inputs))) | |
(set-path-environment-variable "CPLUS_INCLUDE_PATH" | |
'("include") | |
input-directories) | |
#t))) | |
;; This needs to be done because CMakeLists.txt sits in a sub dir | |
(replace | |
'configure | |
(lambda* (#:key outputs #:allow-other-keys) | |
(let* ((out (assoc-ref outputs "out")) | |
(abs-srcdir (getcwd)) | |
(srcdir (string-append "../" (basename abs-srcdir) "/llvm"))) | |
(format #t "---- source directory: ~s (relative from build: ~s) ----~%" | |
abs-srcdir srcdir) | |
(mkdir "../build") | |
(chdir "../build") | |
(invoke | |
"cmake" | |
srcdir | |
"-DCMAKE_BUILD_TYPE=Release" | |
(string-append "-DCMAKE_INSTALL_PREFIX=" out) | |
"-DCMAKE_INSTALL_LIBDIR=lib" | |
"-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE" | |
(string-append "-DCMAKE_INSTALL_RPATH=" out "/lib") | |
"-DCMAKE_VERBOSE_MAKEFILE=ON" | |
"-DLLVM_ENABLE_PROJECTS=clang;compiler-rt;lld"))))))) | |
(inputs `(("python" ,python) | |
("zlib" ,zlib))) | |
(synopsis | |
"Optimizing compiler infrastructure") | |
(description "") | |
(home-page "https://www.llvm.org") | |
(license license:asl2.0))) | |
(define zig | |
(package | |
(name "zig") | |
(version "0.8.0+9910bfa6d") | |
(source (origin | |
(method git-fetch) | |
(uri (git-reference | |
(url "https://github.com/ziglang/zig.git") | |
(commit (substring version 6)))) | |
(sha256 | |
(base32 | |
"0cxik213wz4n3hvlc7wsr75fkg1abhzvnxm6zww1j8dlrzg88hcg")))) | |
(build-system cmake-build-system) | |
(arguments '(#:configure-flags '() | |
#:tests? #f | |
#:phases (modify-phases %standard-phases | |
(add-before 'build 'fix-zig-cache-dir | |
(lambda _ | |
(setenv "XDG_CACHE_HOME" (getenv "TMPDIR")) | |
#t))))) | |
(inputs `(("llvm-for-zig" ,llvm-for-zig) | |
("zlib" ,zlib))) | |
(synopsis | |
"A general-purpose programming language and toolchain.") | |
(description | |
"Zig is a general-purpose programming language and toolchain for | |
maintaining robust, optimal, and reusable software.") | |
(home-page "https://ziglang.org") | |
(license license:expat))) ;; MIT | |
(define zls | |
(package | |
(name "zls") | |
(version "affbd2d") | |
(source (origin | |
(method git-fetch) | |
(uri (git-reference | |
(url "https://github.com/zigtools/zls.git") | |
(commit version))) | |
(sha256 | |
(base32 | |
"1dmsmr3ak0vaxz7qxf4h2hrnf0bkcpmvsgb7l3n6z533fhb0an6n")))) | |
(build-system trivial-build-system) | |
(arguments `(#:modules ((guix build utils)) | |
#:builder | |
(begin | |
(use-modules (guix build utils)) | |
(let* ((srcdir (assoc-ref %build-inputs "source")) | |
(outdir (assoc-ref %outputs "out")) | |
(tmpdir (getenv "TMPDIR")) | |
(build-srcdir (string-append tmpdir "/source")) | |
(bin-outdir (string-append outdir "/bin")) | |
(zig-out (assoc-ref %build-inputs "zig"))) | |
(copy-recursively srcdir build-srcdir) | |
(chdir build-srcdir) | |
(setenv "HOME" tmpdir) | |
(set-path-environment-variable "PATH" '("bin") `(,zig-out)) | |
(invoke "zig" | |
"build" | |
"-Drelease-safe") | |
(install-file (string-append build-srcdir "/zig-out/bin/zls") bin-outdir) | |
#t)))) | |
(inputs `(("zig" ,zig))) | |
(synopsis "The Zig Language Server") | |
(description "") | |
(home-page "https://github.com/zigtools/zls") | |
(license license:expat))) ;; MIT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment