! Copyright (C) 2023 Doug Coleman.
! See https://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs cli.git combinators
-combinators.short-circuit continuations formatting github
-http.client io.directories io.files io.files.info io.files.temp
-io.launcher io.pathnames json kernel layouts math namespaces
-semver sequences sequences.extras sorting sorting.human
-sorting.specification splitting system unicode ;
+combinators.extras combinators.short-circuit continuations
+formatting github http.client io.directories io.files
+io.files.info io.files.temp 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 ]
+INITIALIZED-SYMBOL: use-github-git-uris [ t ]
+
: dll-out-directory ( -- path )
vm-path parent-directory cell-bits "dlls%s-out" sprintf append-path
dup make-directories ;
: with-build-directory ( quot -- ) [ "build" ] dip with-build-directory-as ; inline
-: empty-directory? ( path -- ? )
- { [ directory? ] [ directory-files empty? ] } 1&& ;
-
-! Windows clears the Factor temp directory but leaves the directory names (?)
-! C:\Users\sheeple\AppData\Local\Temp\factorcode.org\Factor>
-: ?sync-repository-as ( url path -- )
- dup { [ git-directory? ] [ ".git" append-path empty-directory? not ] } 1&&
- [ dup ?delete-tree ] unless
- sync-repository-as wait-for-success ;
-
: temp-directory-cpu ( -- path )
temp-directory cpu name>> append-path ;
: with-temp-cpu-directory ( quot -- )
- [ temp-directory-cpu ] dip with-directory ; inline
+ [ temp-directory-cpu dup make-directories ] dip with-directory ; inline
+
+: temp-directory-gitlab ( -- path )
+ temp-directory "gitlab" append-path ;
+
+: with-temp-gitlab-org-directory ( base org/user quot -- )
+ [ append-path temp-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-https-uri ( base org/user project -- uri ) "https://%s/%s/%s" sprintf ;
-: with-updated-git-repo-as ( git-uri path quot -- )
- temp-directory-cpu make-directories
+: 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-repository-as ] keep
- prepend-current-path _ with-directory
+ _ sync-repository wait-for-success
+ ] with-temp-gitlab-org-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 temp-directory-gitlab prepend-path ] dip ] 4bi
+ '[
+ _ _ [ ?delete-tree ] [ git-clone-as wait-for-success ] [ ] tri
+ ] with-temp-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-temp-cpu-directory ; inline
+
+: with-updated-gitlab-repo ( base org/user project quot -- )
+ [ dup git-directory-name ] dip with-updated-gitlab-repo-as ; inline
+
+: temp-directory-github ( -- path )
+ temp-directory "github" append-path ;
+
+: with-temp-github-directory ( org/user quot -- )
+ [ temp-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-repository-as wait-for-success
+ ] with-temp-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 temp-directory-github prepend-path ] dip ] 3bi
+ '[
+ _ _ [ ?delete-tree ] [ git-clone-as wait-for-success ] [ ] tri
+ ] with-temp-cpu-directory ;
+
+: with-updated-github-repo-as ( org/user project build-path-as quot -- )
+ [ sync-github-pristine-and-clone-build-repository-as ] dip
+ '[
+ _ prepend-current-path _ with-directory
] with-temp-cpu-directory ; inline
-: with-updated-git-repo ( git-uri quot -- )
- [ dup git-directory-name ] dip with-updated-git-repo-as ; inline
+: with-updated-github-repo ( org/user project quot -- )
+ [ dup git-directory-name ] dip with-updated-github-repo-as ; inline
: ?download ( path -- )
dup file-name file-exists? [ drop ] [ download ] if ; inline
] with-tar-gz ;
: build-winflexbison ( -- )
- "https://github.com/lexxmark/winflexbison.git" [
+ "lexxmark" "winflexbison" [
[
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-git-repo ;
+ ] with-updated-github-repo ;
: build-blas ( -- )
- "https://github.com/xianyi/OpenBLAS.git" [
+ "xianyi" "OpenBLAS" [
[
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-git-repo ;
+ ] with-updated-github-repo ;
: build-openssl-32-dlls ( -- )
- "http://github.com/openssl/openssl.git" [
+ "openssl" "openssl" [
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-git-repo ;
+ ] with-updated-github-repo ;
: build-openssl-64-dlls ( -- )
- "https://github.com/openssl/openssl.git" [
+ "openssl" "openssl" [
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-git-repo ;
+ ] with-updated-github-repo ;
: build-openssl-dlls ( -- )
32-bit? [ build-openssl-32-dlls ] [ build-openssl-64-dlls ] if ;
: build-cairo-dll ( -- )
- "https://github.com/freedesktop/cairo.git" [
+ "gitlab.freedesktop.org" "cairo" "cairo" [
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-git-repo ;
+ ] with-updated-gitlab-repo ;
: latest-libressl ( -- path )
"https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/" [
] with-tar-gz ;
: build-openal-dll ( -- )
- "https://github.com/kcat/openal-soft.git" [
+ "kcat" "openal-soft" [
[
32-bit? [
{
] if
"Release/OpenAL32.dll" copy-output-file
] with-build-directory
- ] with-updated-git-repo ;
+ ] with-updated-github-repo ;
: latest-pcre-tar-gz ( -- path )
"https://ftp.exim.org/pub/pcre/" [
] with-tar-gz ;
: build-pcre2-dll ( -- )
- "https://github.com/PCRE2Project/pcre2.git" [
+ "PCRE2Project" "pcre2" [
[
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-git-repo ;
+ ] with-updated-github-repo ;
! choco install -y meson winflexbison3
: build-postgres-dll ( -- )
- "https://github.com/postgres/postgres" [
+ "postgres" "postgres" [
"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-git-repo ;
+ ] with-updated-github-repo ;
! choco install -y glfw3
: build-raylib-dll ( -- )
- "https://github.com/raysan5/raylib.git" [
+ "raysan5" "raylib" [
[
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-git-repo ;
+ ] with-updated-github-repo ;
: build-raygui-dll ( -- )
- "https://github.com/raysan5/raygui.git" [
+ "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
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
] if
"raygui.dll" copy-output-file
- ] with-updated-git-repo ;
+ ] with-updated-github-repo ;
: build-snappy-dll ( -- )
- "https://github.com/google/snappy.git" [
+ "google" "snappy" [
[
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-git-repo ;
+ ] with-updated-github-repo ;
: build-sqlite3-dll ( -- )
- "https://github.com/sqlite/sqlite.git" [
+ "sqlite" "sqlite" [
qw{ nmake /f Makefile.msc clean } try-process
qw{ nmake /f Makefile.msc } try-process
"sqlite3.dll" copy-output-file
- ] with-updated-git-repo ;
+ ] with-updated-github-repo ;
: build-yaml-dll ( -- )
- "https://github.com/yaml/libyaml.git" [
+ "yaml" "libyaml" [
[
32-bit? [
qw{ cmake -DBUILD_SHARED_LIBS=ON -A Win32 .. } try-process
"Release/yaml.dll" copy-output-file
] with-build-directory
- ] with-updated-git-repo ;
+ ] with-updated-github-repo ;
: build-zeromq-dll ( -- )
- "https://github.com/zeromq/libzmq.git" [
+ "zeromq" "libzmq" [
[
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-git-repo ;
+ ] with-updated-github-repo ;
: build-zlib-dll ( -- )
- "https://github.com/madler/zlib" [
+ "madler" "zlib" [
qw{ nmake /f win32/Makefile.msc clean } try-process
qw{ nmake /f win32/Makefile.msc } try-process
"zlib1.dll" copy-output-file
- ] with-updated-git-repo ;
+ ] with-updated-github-repo ;
: build-lz4 ( -- )
- "https://github.com/lz4/lz4.git" [
+ "lz4" "lz4" [
"build/cmake" [
[
32-bit? [
"Release/lz4.dll" copy-output-file
] with-build-directory
] with-directory
- ] with-updated-git-repo ;
+ ] with-updated-github-repo ;
: build-zstd-dll ( -- )
- "https://github.com/facebook/zstd.git" [
+ "facebook" "zstd" [
32-bit? [
qw{
meson setup
{ "ninja" } try-process
"lib/zstd-1.dll" copy-output-file
] with-directory
- ] with-updated-git-repo ;
+ ] with-updated-github-repo ;
! 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