! Copyright (C) 2023 Doug Coleman.
! See https://factorcode.org/license.txt for BSD license.
-USING: accessors arrays assocs cli.git combinators
-combinators.extras combinators.short-circuit continuations
-formatting github http.client io.directories io.files
-io.files.info io.launcher io.pathnames json kernel
-layouts math namespaces namespaces.extras semver sequences
-sequences.extras sorting sorting.human sorting.specification
-splitting system unicode ;
+USING: accessors arrays assocs calendar calendar.format cli.git
+combinators combinators.extras combinators.short-circuit
+continuations formatting github http.client io io.directories
+io.encodings.utf8 io.files io.files.info io.launcher
+io.pathnames json kernel layouts math namespaces
+namespaces.extras semver sequences sequences.extras sorting
+sorting.human sorting.specification splitting system unicode ;
IN: build-from-source
INITIALIZED-SYMBOL: use-gitlab-git-uris [ f ]
: build-from-source-directory-gitlab ( -- path )
get-build-from-source-directory "gitlab" append-path ;
-: with-build-from-source-gitlab-org-directory ( base org/user quot -- )
- [ append-path build-from-source-directory-gitlab prepend-path dup make-directories ] dip with-directory ; inline
+: gitlab-disk-path ( base org/user project -- path )
+ 3append-path
+ build-from-source-directory-gitlab prepend-path absolute-path ;
+
+: gitlab-tag-disk-checkout-path ( base org/user project tag -- path )
+ [ gitlab-disk-path ] dip append-path absolute-path ;
+
+: with-build-from-source-gitlab-bare-directory ( base org/user quot -- )
+ [ build-from-source-directory-gitlab prepend-path dup make-directories ] dip with-directory ; inline
: gitlab-git-uri ( base org/user project -- uri ) "git://%s/%s/%s" sprintf ;
: gitlab-http-uri ( base org/user project -- uri ) "http://%s/%s/%s" sprintf ;
: gitlab-uri ( base org/user project -- uri )
use-gitlab-git-uris get [ gitlab-git-uri ] [ gitlab-https-uri ] if ;
-! "gitlab.freedesktop.org" "cairo" "cairo"
-: sync-gitlab-pristine-repository-as ( base org/user project -- )
- [ drop ] [ gitlab-uri ] 3bi
+: sync-gitlab-bare-repository ( base org/user project -- )
+ [ 2drop ] [ gitlab-uri ] [ nipd append-path ] 3tri
'[
- _ sync-repository wait-for-success
- ] with-build-from-source-gitlab-org-directory ;
+ _ _ sync-bare-repository-as wait-for-success
+ ] with-build-from-source-gitlab-bare-directory ;
-: sync-gitlab-pristine-and-clone-build-repository-as ( base org/user project build-path -- build-path )
- [ drop sync-gitlab-pristine-repository-as ]
- [ [ append-path append-path build-from-source-directory-gitlab prepend-path absolute-path ] dip ] 4bi
- '[
- _ _ [ ?delete-tree ] [ git-clone-as wait-for-success ] [ ] tri
- ] with-build-from-source-cpu-directory ;
-
-: with-updated-gitlab-repo-as ( base org/user project build-path-as quot -- )
- [ sync-gitlab-pristine-and-clone-build-repository-as ] dip
- '[
- _ prepend-current-path _ with-directory
- ] with-build-from-source-cpu-directory ; inline
-
-: with-updated-gitlab-repo ( base org/user project quot -- )
- [ dup git-directory-name ] dip with-updated-gitlab-repo-as ; inline
+: with-bare-gitlab-repo ( base org/user project quot -- )
+ [
+ [ sync-gitlab-bare-repository ]
+ [ gitlab-disk-path ] 3bi
+ ] dip with-directory ; inline
: build-from-source-directory-github ( -- path )
get-build-from-source-directory "github" append-path ;
-: with-build-from-source-github-directory ( org/user quot -- )
+: github-disk-path ( org/user project -- path )
+ append-path
+ build-from-source-directory-github prepend-path absolute-path ;
+
+: github-tag-disk-checkout-path ( org/user project tag -- path )
+ [ github-disk-path ] dip append-path absolute-path ;
+
+: with-build-from-source-github-bare-directory ( org/user quot -- )
[ build-from-source-directory-github prepend-path dup make-directories ] dip with-directory ; inline
: github-uri ( org/user project -- uri )
use-github-git-uris get [ github-git-uri ] [ github-https-uri ] if ;
-: sync-github-pristine-repository-as ( org/user project -- )
- [ drop ] [ github-uri ] [ nip ] 2tri
+: sync-github-bare-repository ( org/user project -- )
+ [ drop ] [ github-uri ] [ nip git-directory-name ] 2tri
'[
- _ _ sync-repository-as wait-for-success
- ] with-build-from-source-github-directory ;
-
-! "factor" "vscode-factor" "factor-buildme-here"
-: sync-github-pristine-and-clone-build-repository-as ( org/user project build-path -- build-path )
- [ drop sync-github-pristine-repository-as ]
- [ [ append-path build-from-source-directory-github prepend-path absolute-path ] dip ] 3bi
+ _ _ sync-bare-repository-as wait-for-success
+ ] with-build-from-source-github-bare-directory ;
+
+: with-github-worktree-tag ( org/user project tag quot -- )
+ [
+ {
+ [ drop sync-github-bare-repository ]
+ [ drop github-disk-path ]
+ [ github-tag-disk-checkout-path ]
+ [ 2nip ]
+ } 3cleave
+ ] dip
'[
- _ _ [ ?delete-tree ] [ git-clone-as wait-for-success ] [ ] tri
- ] with-build-from-source-cpu-directory ;
-
-: with-updated-github-repo-as ( org/user project build-path-as quot -- )
- [ sync-github-pristine-and-clone-build-repository-as ] dip
+ _ _
+ over "factor-build-completed" append-path dup file-exists? [
+ utf8 file-contents
+ "%s\n- %s already built at %s" sprintf print
+ ] [
+ [
+ over "%s\n- deleting old build..." sprintf write
+ 2dup [ ?delete-tree "deleted!" print ]
+ [ "- %s building..." sprintf write ] bi*
+ [ git-worktree-force-add wait-for-success ] keepd
+ _ with-directory
+ "done!" print
+ now timestamp>rfc3339
+ ] dip utf8 set-file-contents
+ ] if
+ ] with-directory ; inline
+
+: with-gitlab-worktree-tag ( base org/user project tag quot -- )
+ [
+ {
+ [ drop sync-gitlab-bare-repository ]
+ [ drop gitlab-disk-path ]
+ [ gitlab-tag-disk-checkout-path ]
+ [ 3nip ]
+ } 4cleave
+ ] dip
'[
- _ prepend-current-path _ with-directory
- ] with-build-from-source-cpu-directory ; inline
-
-: with-updated-github-repo ( org/user project quot -- )
- [ dup git-directory-name ] dip with-updated-github-repo-as ; inline
+ _ _
+ over "factor-build-completed" append-path dup file-exists? [
+ utf8 file-contents
+ "%s\n- %s already built at %s" sprintf print
+ ] [
+ [
+ over "%s\n- deleting old build..." sprintf write
+ 2dup [ ?delete-tree "deleted!" print ]
+ [ "- %s building..." sprintf write ] bi*
+ [ git-worktree-force-add wait-for-success ] keepd
+ _ with-directory
+ "done!" print
+ now timestamp>rfc3339
+ ] dip utf8 set-file-contents
+ ] if
+ ] with-directory ; inline
: ?download ( path -- )
dup file-name file-exists? [ drop ] [ download ] if ; inline
: latest-solr ( -- tag-json semver ) "apache" "solr" "releases/solr" latest-semver-tags-matching ;
: latest-lucene ( -- tag-json semver ) "apache" "lucene" "releases/lucene" latest-semver-tags-matching ;
-: python-tags ( -- tags )
- "python" "cpython" "v" list-repository-tags-matching
+: digit-or-dot? ( str -- ? )
+ { [ digit? ] [ CHAR: . = ] } 1|| ;
+
+: tag-refs ( tags -- tags' )
[ "ref" of ] map
[ "refs/tags/" ?head drop ] map ;
+: python-tags ( -- tags )
+ "python" "cpython" "v" list-repository-tags-matching tag-refs ;
+
: tags>latest-python2 ( tags -- tag ) [ "v2." head? ] filter latest-python ;
: latest-python2 ( -- tag ) python-tags tags>latest-python2 ;
-: tags>latest-python3 ( tags -- tag ) [ "v3." head? ] filter latest-python ;
+: tags>latest-python3 ( tags -- tag )
+ [ "v3." head? ] filter
+ [ "." split1-last nip [ digit? ] all? ] filter
+ latest-python ;
: latest-python3 ( -- tag ) python-tags tags>latest-python3 ;
! Copyright (C) 2023 Doug Coleman.
! See https://factorcode.org/license.txt for BSD license.
-USING: accessors build-from-source continuations environment
-html.parser html.parser.analyzer http.client io.directories
-io.files.temp io.launcher io.pathnames kernel layouts qw
-sequences sorting.human windows.shell32 ;
+USING: accessors ascii build-from-source cli.git
+combinators.short-circuit combinators.smart continuations
+environment github html.parser html.parser.analyzer http.client
+io.directories io.files.temp io.launcher io.pathnames kernel
+layouts math namespaces qw sequences sorting.human splitting
+windows.shell32 ;
IN: build-from-source.windows
! choco install -y meson StrawberryPerl nasm winflexbison3 glfw3 jom
] with-build-directory
] with-tar-gz ;
+: winflexbison-versions ( -- seq )
+ "lexxmark" "winflexbison" "v" list-repository-tags-matching
+ tag-refs [ "v." head? ] reject human-sort ;
+
: build-winflexbison ( -- )
- "lexxmark" "winflexbison" [
+ "lexxmark" "winflexbison" winflexbison-versions last [
[
qw{ cmake .. } try-process
qw{ cmake --build . --config Release --target package } try-process
] with-build-directory
"bin/Release/win_bison.exe" "bison.exe" copy-vm-file-as
"bin/Release/win_flex.exe" "flex.exe" copy-vm-file-as
- ] with-updated-github-repo ;
+ ] with-github-worktree-tag ;
+
+: blas-versions ( -- seq )
+ "xianyi" "OpenBLAS" "v" list-repository-tags-matching
+ tag-refs human-sort ;
: build-blas ( -- )
- "xianyi" "OpenBLAS" [
+ "xianyi" "OpenBLAS" blas-versions last [
[
32-bit? [
{ "cmake" "-G" "Visual Studio 17 2022" "-A" "Win32" "-DCMAKE_BUILD_TYPE=Release" "-DBUILD_SHARED_LIBS=ON" ".." } try-process
] if
"lib/RELEASE/openblas.dll" "blas.dll" copy-output-file-as
] with-build-directory
- ] with-updated-github-repo ;
+ ] with-github-worktree-tag ;
+
+: openssl-versions ( -- seq )
+ "openssl" "openssl" "openssl-" list-repository-tags-matching
+ tag-refs human-sort ;
: build-openssl-32-dlls ( -- )
- "openssl" "openssl" [
+ "openssl" "openssl" openssl-versions last [
check-perl
"ProgramW6432" os-env program-files or
"NASM/nasm.exe" append-path "nasm.exe" prepend-current-path copy-file
qw{ perl Configure -DOPENSSL_PIC VC-WIN32 /FS } try-process
have-jom? qw{ jom -j 32 } { "nmake" } ? try-process
{ "libssl-3.dll" "libcrypto-3.dll" } copy-output-files
- ] with-updated-github-repo ;
+ ] with-github-worktree-tag ;
: build-openssl-64-dlls ( -- )
- "openssl" "openssl" [
+ "openssl" "openssl" openssl-versions last [
check-perl
program-files "NASM/nasm.exe" append-path "nasm.exe" prepend-current-path copy-file
check-nasm
qw{ perl Configure -DOPENSSL_PIC VC-WIN64A /FS } try-process
have-jom? qw{ jom -j 32 } { "nmake" } ? try-process
{ "apps/libssl-3-x64.dll" "apps/libcrypto-3-x64.dll" } copy-output-files
- ] with-updated-github-repo ;
+ ] with-github-worktree-tag ;
: build-openssl-dlls ( -- )
32-bit? [ build-openssl-32-dlls ] [ build-openssl-64-dlls ] if ;
-: build-cairo-dll ( -- )
+: cairo-versions ( -- seq )
"gitlab.freedesktop.org" "cairo" "cairo" [
+ git-tag*
+ ] with-bare-gitlab-repo
+ [ [ digit-or-dot? ] all? ] filter
+ human-sort ;
+
+: build-cairo-dll ( -- )
+ "gitlab.freedesktop.org" "cairo" "cairo" cairo-versions last [
qw{ meson setup --force-fallback-for=freetype2,fontconfig,zlib,expat,expat_dep build } try-process
"build" prepend-current-path
[ { "ninja" } try-process ] with-directory
"testmodulea.dll"
"testmoduleb.dll"
} delete-output-files
- ] with-updated-gitlab-repo ;
+ ] with-gitlab-worktree-tag ;
: latest-libressl ( -- path )
"https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/" [
] with-build-directory
] with-tar-gz ;
+: openal-versions ( -- seq )
+ "kcat" "openal-soft" "" list-repository-tags-matching
+ tag-refs
+ [ [ digit-or-dot? ] all? ] filter
+ human-sort ;
+
: build-openal-dll ( -- )
- "kcat" "openal-soft" [
+ "kcat" "openal-soft" openal-versions last [
[
32-bit? [
{
] if
"Release/OpenAL32.dll" copy-output-file
] with-build-directory
- ] with-updated-github-repo ;
+ ] with-github-worktree-tag ;
+
+: grpc-versions ( -- seq )
+ "grpc" "grpc" "v" list-repository-tags-matching
+ tag-refs human-sort ;
: build-grpc-dll ( -- )
- "grpc" "grpc" [
+ "grpc" "grpc" grpc-versions last [
qw{ git submodule init } try-process
qw{ git submodule update } try-process
qw{ rm -rf third_party\boringssl-with-bazel } try-process
"bin/Release/abseil_dll.dll" copy-output-file
"bin/Release/protoc.exe" copy-output-file
] with-build-directory-as
- ] with-updated-github-repo ;
+ ] with-github-worktree-tag ;
: latest-pcre-tar-gz ( -- path )
"https://ftp.exim.org/pub/pcre/" [
] with-build-directory
] with-tar-gz ;
+: pcre2-versions ( -- seq )
+ "PCRE2Project" "pcre2" "" list-repository-tags-matching
+ tag-refs human-sort ;
+
: build-pcre2-dll ( -- )
- "PCRE2Project" "pcre2" [
+ "PCRE2Project" "pcre2" pcre2-versions last [
[
32-bit? [
qw{ cmake -A Win32 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DPCRE2_SUPPORT_UNICODE=ON -DPCRE2_SUPPORT_LIBZ=OFF -DPCRE2_SUPPORT_LIBBZ2=OFF -DPCRE2_SUPPORT_LIBEDIT=OFF -DPCRE2_SUPPORT_LIBREADLINE=OFF .. } try-process
] if
{ "Release/pcre2-8.dll" "Release/pcre2-posix.dll" } copy-output-files
] with-build-directory
- ] with-updated-github-repo ;
+ ] with-github-worktree-tag ;
+
+: postgres-versions ( -- seq )
+ "postgres" "postgres" "REL_" list-repository-tags-matching
+ tag-refs
+ ! [ "_" split1-last nip [ digit? ] all? ] filter ! no RC1 or BETA1
+ human-sort ;
! choco install -y meson winflexbison3
: build-postgres-dll ( -- )
- "postgres" "postgres" [
+ "postgres" "postgres" postgres-versions last [
"src/tools/msvc/clean.bat" prepend-current-path try-process
qw{ meson setup build } try-process
"build" prepend-current-path
[ { "ninja" } try-process ] with-directory
"build/src/interfaces/libpq/libpq.dll" copy-output-file
- ] with-updated-github-repo ;
+ ] with-github-worktree-tag ;
+
+: raylib-versions ( -- seq )
+ "raysan5" "raylib" "" list-repository-tags-matching
+ tag-refs human-sort ;
! choco install -y glfw3
: build-raylib-dll ( -- )
- "raysan5" "raylib" [
+ "raysan5" "raylib" raylib-versions last [
[
32-bit? [
qw{ cmake -A Win32 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DBUILD_EXAMPLES=OFF -DUSE_EXTERNAL_GLFW=OFF .. } try-process
] if
"raylib/Release/raylib.dll" copy-output-file
] with-build-directory
- ] with-updated-github-repo ;
+ ] with-github-worktree-tag ;
+
+: raygui-versions ( -- seq )
+ "raysan5" "raygui" "" list-repository-tags-matching
+ tag-refs human-sort ;
+
+:: build-raygui-dll ( -- )
+ "raysan5" "raygui" raygui-versions last [
+ "raysan5" "raylib" raylib-versions last github-tag-disk-checkout-path :> $raylib-dir
+ $raylib-dir "src" append-path :> $raylib-src
+ $raylib-dir "build/raylib/Release/raylib.lib" append-path :> $raylib-lib
-: build-raygui-dll ( -- )
- "raysan5" "raygui" [
"src/raygui.h" "src/raygui.c" copy-file
32-bit? [
- qw{ cl /O2 /I ../raylib/src/ /D_USRDLL /D_WINDLL /DRAYGUI_IMPLEMENTATION /DBUILD_LIBTYPE_SHARED src/raygui.c /LD /Feraygui.dll /link /LIBPATH ../raylib/build/raylib/Release/raylib.lib /subsystem:windows /machine:x86 } try-process
+ [ "cl" "/O2" "/I" $raylib-src "/D_USRDLL" "/D_WINDLL" "/DRAYGUI_IMPLEMENTATION" "/DBUILD_LIBTYPE_SHARED" "src/raygui.c" "/LD" "/Feraygui.dll" "/link" "/LIBPATH" $raylib-lib "/subsystem:windows" "/machine:x86" ] output>array try-process
] [
- qw{ cl /O2 /I ../raylib/src/ /D_USRDLL /D_WINDLL /DRAYGUI_IMPLEMENTATION /DBUILD_LIBTYPE_SHARED src/raygui.c /LD /Feraygui.dll /link /LIBPATH ../raylib/build/raylib/Release/raylib.lib /subsystem:windows /machine:x64 } try-process
+ [ "cl" "/O2" "/I" $raylib-src "/D_USRDLL" "/D_WINDLL" "/DRAYGUI_IMPLEMENTATION" "/DBUILD_LIBTYPE_SHARED" "src/raygui.c" "/LD" "/Feraygui.dll" "/link" "/LIBPATH" $raylib-lib "/subsystem:windows" "/machine:x64" ] output>array try-process
] if
"raygui.dll" copy-output-file
- ] with-updated-github-repo ;
+ ] with-github-worktree-tag ;
+
+: ripgrep-versions ( -- seq )
+ "BurntSushi" "ripgrep" "" list-repository-tags-matching
+ tag-refs human-sort ;
: build-ripgrep ( -- )
- "BurntSushi" "ripgrep" [
+ "BurntSushi" "ripgrep" ripgrep-versions last [
qw{ cargo build --release } try-process
"target/release/rg.exe" copy-output-file
- ] with-updated-github-repo ;
+ ] with-github-worktree-tag ;
+
+: snappy-versions ( -- seq )
+ "google" "snappy" "" list-repository-tags-matching
+ tag-refs human-sort ;
: build-snappy-dll ( -- )
- "google" "snappy" [
+ "google" "snappy" snappy-versions last [
[
32-bit? [
qw{ cmake -A Win32 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DSNAPPY_BUILD_TESTS=OFF -DSNAPPY_BUILD_BENCHMARKS=OFF .. } try-process
] if
"Release/snappy.dll" copy-output-file
] with-build-directory
- ] with-updated-github-repo ;
+ ] with-github-worktree-tag ;
+
+: sqlite-versions ( -- seq )
+ "sqlite" "sqlite" "version-" list-repository-tags-matching
+ tag-refs human-sort ;
-: build-sqlite3-dll ( -- )
- "sqlite" "sqlite" [
+: build-sqlite-dll ( -- )
+ "sqlite" "sqlite" sqlite-versions last [
qw{ nmake /f Makefile.msc clean } try-process
qw{ nmake /f Makefile.msc } try-process
"sqlite3.dll" copy-output-file
- ] with-updated-github-repo ;
+ ] with-github-worktree-tag ;
+
+: duckdb-versions ( -- seq )
+ "duckdb" "duckdb" "v" list-repository-tags-matching
+ tag-refs human-sort ;
: build-duckdb-dll ( -- )
- "duckdb" "duckdb" [
+ "duckdb" "duckdb" duckdb-versions last [
[
32-bit? [
qw{ cmake -DBUILD_SHARED_LIBS=ON -A Win32 .. } try-process
"src/Release/duckdb.dll" copy-output-file
"Release/duckdb.exe" copy-output-file
] with-build-directory
- ] with-updated-github-repo ;
+ ] with-github-worktree-tag ;
+
+: yaml-versions ( -- seq )
+ "yaml" "libyaml" "" list-repository-tags-matching
+ tag-refs [ [ digit-or-dot? ] all? ] filter human-sort ;
: build-yaml-dll ( -- )
- "yaml" "libyaml" [
+ "yaml" "libyaml" yaml-versions last [
[
32-bit? [
qw{ cmake -DBUILD_SHARED_LIBS=ON -A Win32 .. } try-process
"Release/yaml.dll" copy-output-file
] with-build-directory
- ] with-updated-github-repo ;
+ ] with-github-worktree-tag ;
+
+: zeromq-versions ( -- seq )
+ "zeromq" "libzmq" "" list-repository-tags-matching
+ tag-refs human-sort ;
: build-zeromq-dll ( -- )
- "zeromq" "libzmq" [
+ "zeromq" "libzmq" zeromq-versions last [
[
32-bit? [
qw{ cmake -DBUILD_SHARED_LIBS=ON -A Win32 .. } try-process
] if
"bin/Release" find-dlls first "libzmq.dll" copy-output-file-as
] with-build-directory
- ] with-updated-github-repo ;
+ ] with-github-worktree-tag ;
+
+: zlib-versions ( -- seq )
+ "madler" "zlib" "v" list-repository-tags-matching
+ tag-refs human-sort ;
: build-zlib-dll ( -- )
- "madler" "zlib" [
+ "madler" "zlib" zlib-versions last [
qw{ nmake /f win32/Makefile.msc clean } try-process
qw{ nmake /f win32/Makefile.msc } try-process
"zlib1.dll" copy-output-file
- ] with-updated-github-repo ;
+ ] with-github-worktree-tag ;
+
+: lz4-versions ( -- seq )
+ "lz4" "lz4" "v" list-repository-tags-matching
+ tag-refs human-sort ;
: build-lz4 ( -- )
- "lz4" "lz4" [
+ "lz4" "lz4" lz4-versions last [
"build/cmake" [
[
32-bit? [
"Release/lz4.dll" copy-output-file
] with-build-directory
] with-directory
- ] with-updated-github-repo ;
+ ] with-github-worktree-tag ;
+
+: zstd-versions ( -- seq )
+ "facebook" "zstd" "v" list-repository-tags-matching
+ tag-refs human-sort ;
: build-zstd-dll ( -- )
- "facebook" "zstd" [
+ "facebook" "zstd" zstd-versions last [
32-bit? [
qw{
meson setup
{ "ninja" } try-process
"lib/zstd-1.dll" copy-output-file
] with-directory
- ] with-updated-github-repo ;
+ ] with-github-worktree-tag ;
! Probably not needed on Windows 10+
: install-windows-redistributable ( -- )
: build-windows-dlls ( -- )
dll-out-directory make-directories
build-winflexbison
- build-cairo-dll
build-openssl-dlls
build-blas
- build-libressl-dlls
- build-fftw-dll
build-openal-dll
- build-pcre-dll
build-pcre2-dll
32-bit? [ build-postgres-dll ] unless
build-raylib-dll
build-raygui-dll
build-snappy-dll
- build-sqlite3-dll
+ build-sqlite-dll
build-yaml-dll
build-zeromq-dll
build-zlib-dll
- build-zstd-dll ;
+ build-zstd-dll
+ build-cairo-dll
+ build-libressl-dlls
+ build-fftw-dll
+ build-pcre-dll ;