Skip to content

Commit 292abc2

Browse files
authored
Gentoo distro build script for 2.6.0 (#1599)
2 parents 773b236 + 556203a commit 292abc2

File tree

4 files changed

+263
-4
lines changed

4 files changed

+263
-4
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ debhelper-build-stamp
5050
clasp.substvars
5151
debian/clasp
5252
debian/files
53+
gentoo/clasp
5354
src/lisp/regression-tests/*.txt
5455
src/lisp/regression-tests/*.bc
5556
src/lisp/regression-tests/*.newfasl
5657
src/analysis/*.lst
5758
src/analysis/*.cc
5859
bench/
59-
repos-*.sexp
60+
repos-*.sexp

gentoo/ebuild.template

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# -*- mode: sh-script; mode: ebuild; -*-
2+
# Copyright 1999-2024 Gentoo Authors
3+
# Distributed under the terms of the GNU General Public License v2 or later.
4+
5+
EAPI=8
6+
7+
CHECKREQS_MEMORY="2G"
8+
LLVM_COMPAT=( {15..18} )
9+
10+
inherit check-reqs edo flag-o-matic llvm-r1 multiprocessing ninja-utils toolchain-funcs
11+
12+
# Dependencies are in two groups: (1) a minimal set which are spec'd in
13+
# this ebuild and must be pre-installed, and (2) an additional set which
14+
# are obtained by the build scripts.
15+
#
16+
# Version N.N.N is a normal release. All necessary sources are wrapped
17+
# up in a tarball, including the additional dependencies but not the
18+
# minimal ebuild set.
19+
#
20+
# Version 9999 is the standard Gentoo "live ebuild" (git HEAD). The
21+
# minimal set of dependencies must already be installed, the Clasp
22+
# sources will be pulled down via git in this ebuild, and then the build
23+
# scripts will pull down the additional set of dependencies, also via
24+
# git.
25+
26+
if [ ${PV} = "9999" ]; then
27+
EGIT_REPO_URI="https://github.com/clasp-developers/clasp"
28+
EGIT_BRANCH="main"
29+
# The app build script will git the dependencies not in BDEPEND.
30+
EGIT_MIN_CLONE_TYPE="shallow"
31+
inherit git-r3
32+
SLOT="0"
33+
else
34+
SRC_URI="https://github.com/clasp-developers/clasp/releases/download/${PV}/${P}.tar.gz"
35+
KEYWORDS="~amd64"
36+
SLOT="0/${PV}"
37+
fi
38+
39+
DESCRIPTION="Common Lisp implementation based on LLVM."
40+
HOMEPAGE="https://github.com/clasp-developers/clasp"
41+
# Primary Clasp and core ECL (src/lisp/kernel/lsp) are LGPL-2+,
42+
# Parts of Clasp are MIT.
43+
# MPS is Sleepycat,
44+
# src/lisp/kernel/clos is LGPL-2+,
45+
# src/lisp/kernel/lsp/loop2.lisp is MIT,
46+
# src/lisp/kernel/lsp/{pprint,format}.lisp are Public Domain by CMU,
47+
# src/lisp/kernel/clos is LGPL-2+
48+
LICENSE="LGPL-2+ Sleepycat MIT public-domain"
49+
50+
IUSE="+bcfaso"
51+
52+
# Clasp needs llvm's libunwind, but runs OK without the Portage
53+
# sys-devel/llvm-libunwind being installed. (Or even an "unwind"
54+
# lib anywhere in installed llvm tree.) Don't question it,
55+
# it's magic.
56+
57+
RDEPEND="sys-devel/binutils:=
58+
$(llvm_gen_dep '
59+
sys-devel/clang:${LLVM_SLOT}=
60+
sys-devel/llvm:${LLVM_SLOT}=
61+
sys-devel/lld:${LLVM_SLOT}=
62+
')
63+
dev-libs/boost:=
64+
>=dev-libs/libfmt-7.1.0
65+
>=dev-libs/gmp-6.0.0[cxx]
66+
virtual/pkgconfig
67+
virtual/libelf:="
68+
DEPEND="${RDEPEND}"
69+
BDEPEND="app-alternatives/ninja
70+
dev-lisp/sbcl"
71+
[ "${PV}" = "2.6.0" ] && BDEPEND+=" dev-util/ctags"
72+
IDEPEND="app-alternatives/ninja
73+
dev-lisp/sbcl"
74+
75+
RESTRICT="strip"
76+
77+
DOCS=(
78+
CONTRIBUTING.md
79+
README.md
80+
RELEASE_NOTES.md
81+
SECURITY.md
82+
)
83+
MANDOCS=( docs/clasp.1 )
84+
85+
pkg_pretend() {
86+
if [ "${PV}" = "9999" ]; then
87+
ewarn "This live ebuild is incompatible with make.conf FEATURE 'network-sandbox'."
88+
ewarn "The koga/ninja build script downloads additional C++ and Common Lisp"
89+
ewarn "dependencies by internally calling git, without going through ebuild"
90+
ewarn "helpers. network-sandbox intentionally prevents all such access."
91+
ewarn "See https://wiki.gentoo.org/wiki/Sandbox_(Portage)"
92+
ewarn " https://bugs.gentoo.org/691472"
93+
fi
94+
}
95+
96+
src_unpack() {
97+
[ -n "${EGIT_REPO_URI}" ] && git-r3_src_unpack
98+
default
99+
}
100+
101+
src_configure() {
102+
# Get job count from MAKEOPTS '-j' flag. Use for Lisp builds and Ninja.
103+
export CLASP_BUILD_JOBS=$(get_makeopts_jobs)
104+
105+
strip-unsupported-flags
106+
# Clasp needs un-stripped binaries.
107+
filter-flags -Wl,-s
108+
filter-ldflags -s
109+
# Clasp build scripts set -fno-omit-fpointer where its needed.
110+
111+
# Set up paths to LLVM components.
112+
llvm-r1_pkg_setup
113+
114+
local myconf=(
115+
--ldflags="${LDFLAGS}"
116+
--jobs=${CLASP_BUILD_JOBS}
117+
--reproducible
118+
--build-path="${S}/build"
119+
--prefix="${EPREFIX}/usr"
120+
--bin-path="${EPREFIX}/usr/bin"
121+
--lib-path="${EPREFIX}/usr/$(get_libdir)/${PF}"
122+
--share-path="${EPREFIX}/usr/share/${PF}"
123+
--pkg-config=$(tc-getPKG_CONFIG)
124+
--ld="lld"
125+
--lisp=sbcl # Upstream really, really prefers SBCL
126+
)
127+
128+
# Yes, we get a pkgcheck VariableScope warning on {ED},
129+
# Unfortunately, the Clasp koga script creates all of the ninja
130+
# scripts at src_configure time, and the generated scripts have no
131+
# provision for looking at DESTDIR at install time. This config
132+
# setting only affects the install-time script, and seems to be the
133+
# least-fragile way to handle it.
134+
myconf+=( --package-path="${ED}" )
135+
136+
# All needed sources are bundled in release tarballs
137+
[ "${PV}" != "9999" ] && myconf+=( --skip-sync )
138+
139+
use bcfaso && myconf+=( --build-mode=bytecode-faso )
140+
141+
edo ./koga "${myconf[@]}"
142+
}
143+
144+
src_compile() {
145+
edob eninja -C "${S}/build"
146+
}
147+
148+
src_test() {
149+
# False positives from backtrace tests
150+
#eninja -C "${S}/build" test
151+
edo "${S}/build/boehmprecise/clasp" --norc --disable-debugger --non-interactive \
152+
--eval '(ext:quit (if (eql (* 6 7) 42) 0 1))'
153+
}
154+
155+
src_install() {
156+
eninja -C "${S}/build" install
157+
dodoc ${DOCS[@]}
158+
dodoc -r licenses
159+
[ -e "${MANDOCS}" ] && doman ${MANDOCS[@]}
160+
}

gentoo/metadata.xml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE pkgmetadata SYSTEM "https://www.gentoo.org/dtd/metadata.dtd">
3+
<pkgmetadata>
4+
<maintainer type="person">
5+
<email>[email protected]</email>
6+
<name>Michael South</name>
7+
</maintainer>
8+
<longdescription>Clasp is a new Common Lisp implementation that
9+
seamlessly interoperates with C++ libraries and programs using LLVM
10+
for compilation to native code.
11+
12+
Building Clasp requires that you already have a running CL compiler.
13+
This is hard-coded to SBCL due to strong preference from upstream.
14+
</longdescription>
15+
<use>
16+
<flag name="bcfaso">Build-mode :bytecode-faso rather than the default
17+
:faso (LLVM binary format). :bytecode-faso leaves the kernel and modules
18+
as FASO but user code is bytecode (faster compilation but slower execution).
19+
</flag>
20+
</use>
21+
<upstream>
22+
<remote-id type="github">clasp-developers/clasp</remote-id>
23+
<maintainer status="active">
24+
<email>[email protected]</email>
25+
<name>Clasp developers</name>
26+
</maintainer>
27+
<changelog>https://github.com/clasp-developers/clasp/blob/main/RELEASE_NOTES.md</changelog>
28+
<doc>https://clasp-developers.github.io/manual.html</doc>
29+
<bugs-to>https://github.com/clasp-developers/clasp/issues/new</bugs-to>
30+
</upstream>
31+
</pkgmetadata>

src/koga/archive.lisp

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
&key archive extensions tag
1010
&allow-other-keys)
1111
(declare (ignore initargs))
12-
(let* ((prefix (format nil "clasp-~a/"
13-
(getf (read-file-form #P"version.sexp" tag) :version)))
12+
(let* ((version (getf (read-file-form #P"version.sexp" tag) :version))
13+
(prefix (format nil "clasp-~a/" version))
1414
(tar-name (concatenate 'string (if (stringp archive) archive "archive") ".tar"))
1515
(gz-name (concatenate 'string tar-name ".gz")))
1616
(uiop:delete-file-if-exists tar-name)
@@ -40,4 +40,71 @@
4040
tar-name temp-path))))
4141
:want-stream-p nil)
4242
(message nil "Compressing archive...")
43-
(run-program (format nil "gzip ~a" tar-name))))
43+
(run-program (format nil "gzip ~a" tar-name))
44+
(generate-ebuild version gz-name)))
45+
46+
(defun generate-ebuild (&optional (version "9999") archive)
47+
(labels ((mk-os-path (&rest args)
48+
;; args: (full-os-path) | (dir fname) | (dir base ext)
49+
(format nil "~<~^~a~^/~a~^.~a~:>" args))
50+
(os-path-fname (path)
51+
(nth-value 2 (uiop:split-unix-namestring-directory-components path)))
52+
(os->cl-path (os-path)
53+
(uiop:ensure-absolute-pathname os-path (uiop:getcwd)))
54+
(fbytes (os-path)
55+
(or (with-open-file (s (os->cl-path os-path) :element-type 'unsigned-byte
56+
:if-does-not-exist nil)
57+
(when s (file-length s)))
58+
0))
59+
(calc-hash (os-path hash-type)
60+
(subseq (uiop:run-program (format nil "cksum -a ~a --untagged \"~a\"" os-path hash-type)
61+
:output :string)
62+
0 128))
63+
(copy-f (src-os-path dest-os-path)
64+
(let ((s-path (os->cl-path src-os-path))
65+
(d-path (os->cl-path dest-os-path)))
66+
(uiop:ensure-all-directories-exist (list d-path))
67+
(uiop:delete-file-if-exists d-path)
68+
(uiop:copy-file s-path d-path))))
69+
(let* ((src-dir "gentoo")
70+
(dest-dir "gentoo/clasp")
71+
(manifest-name "Manifest")
72+
(pkg-ver (concatenate 'string "clasp-" version))
73+
;; Files to copy: each entry (manifest-label source dest)
74+
(flist `(,@(unless (equal version "9999")
75+
`(("EBUILD" ,(mk-os-path src-dir "ebuild.template")
76+
,(mk-os-path dest-dir pkg-ver "ebuild"))))
77+
("EBUILD" ,(mk-os-path src-dir "ebuild.template")
78+
,(mk-os-path dest-dir "clasp-9999.ebuild"))
79+
("MISC" ,(mk-os-path src-dir "metadata.xml")
80+
,(mk-os-path dest-dir "metadata.xml"))
81+
,@(when archive `(("DIST" nil ,(mk-os-path archive))))))
82+
;; --
83+
(manifest-path (os->cl-path (mk-os-path dest-dir manifest-name)))
84+
(manifest-temp-path (uiop:tmpize-pathname manifest-path)))
85+
(message nil "Creating Gentoo/Portage distro files for ~a..." pkg-ver)
86+
(uiop:ensure-all-directories-exist (list manifest-temp-path))
87+
(with-open-file (mfst-dest manifest-temp-path :direction :output :if-exists :supersede)
88+
;; Copy existing Manifest into temp file, dropping entries we're about
89+
;; to create.
90+
(with-open-file (mfst-src manifest-path :direction :input :if-does-not-exist nil)
91+
(when mfst-src
92+
(loop
93+
for line = (read-line mfst-src nil nil)
94+
while line
95+
;; Omit manifest entries we're about to create
96+
unless (some (lambda (x) (search (os-path-fname (third x)) line)) flist)
97+
do (write-line line mfst-dest))))
98+
;; Copy files, add them to manifest
99+
(loop for (mfst-type s-os-path d-os-path) in flist
100+
when s-os-path
101+
do (copy-f s-os-path d-os-path)
102+
do (with-standard-io-syntax
103+
(format mfst-dest "~a ~a ~d BLAKE2B ~a SHA512 ~a~%"
104+
mfst-type
105+
(os-path-fname d-os-path)
106+
(fbytes d-os-path)
107+
(calc-hash "blake2b" d-os-path)
108+
(calc-hash "sha512" d-os-path)))))
109+
(uiop:rename-file-overwriting-target manifest-temp-path manifest-path)
110+
manifest-path)))

0 commit comments

Comments
 (0)