lumo 1.9.0 -> 1.10.1 plus darwin support

This commit is contained in:
hlolli
2020-02-19 23:16:40 +01:00
parent 43a775649c
commit ef712ff2f5
9 changed files with 1465 additions and 1376 deletions

View File

@@ -1,18 +1,30 @@
{ stdenv, lib, fetchurl, clojure,
nodejs, jre, unzip, nodePackages,
python, openssl, pkgs }:
{ stdenv
, lib
, fetchurl
, clojure
, gnutar
, nodejs
, jre
, unzip
, nodePackages
, xcbuild
, python
, openssl
, pkgs
, fetchgit
, darwin
}:
let
version = "1.10.1";
nodeVersion = "11.13.0";
nodeSources = fetchurl {
url = "https://nodejs.org/dist/v${nodeVersion}/node-v${nodeVersion}.tar.gz";
sha256 = "1cjzjbshxnysxkvbf41p3m8298cnhs9kfvdczgvvvlp6w16x4aac";
};
lumo-internal-classpath = "LUMO__INTERNAL__CLASSPATH";
let # packageJSON=./package.json;
version = "1.9.0";
nodeVersion = "10.9.0";
nodeSources = fetchurl {
url="https://nodejs.org/dist/v${nodeVersion}/node-v${nodeVersion}.tar.gz";
sha256="0wgawq3wzw07pir73bxz13dggcc1fj0538y7y69n3cc0a2kiplqy";
};
lumo-internal-classpath = "LUMO__INTERNAL__CLASSPATH";
# as found in cljs/snapshot/lumo/repl.cljs
requireDeps = '' \
# as found in cljs/snapshot/lumo/repl.cljs
requireDeps = '' \
cljs.analyzer \
cljs.compiler \
cljs.env \
@@ -50,104 +62,125 @@ let # packageJSON=./package.json;
lumo.js-deps \
lumo.common '';
compileClojurescript = (simple: ''
(require '[cljs.build.api :as cljs])
(cljs/build \"src/cljs/snapshot\"
{:optimizations ${if simple then ":simple" else ":none"}
:main 'lumo.core
:cache-analysis true
:source-map false
:dump-core false
:static-fns true
:optimize-constants false
:npm-deps false
:verbose true
:closure-defines {'cljs.core/*target* \"nodejs\"
'lumo.core/*lumo-version* \"${version}\"}
:compiler-stats true
:process-shim false
:fn-invoke-direct true
:parallel-build false
:browser-repl false
:target :nodejs
:hashbang false
;; :libs [ \"src/cljs/bundled\" \"src/js\" ]
:output-dir ${if simple
then ''\"cljstmp\"''
else ''\"target\"''}
:output-to ${if simple
then ''\"cljstmp/main.js\"''
else ''\"target/deleteme.js\"'' }})
'');
compileClojurescript = (simple: ''
(require '[cljs.build.api :as cljs])
(cljs/build \"src/cljs/snapshot\"
{:optimizations ${if simple then ":simple" else ":none"}
:main 'lumo.core
:cache-analysis true
:source-map false
:dump-core false
:static-fns true
:optimize-constants false
:npm-deps false
:verbose true
:closure-defines {'cljs.core/*target* \"nodejs\"
'lumo.core/*lumo-version* \"${version}\"}
:compiler-stats true
:process-shim false
:fn-invoke-direct true
:parallel-build false
:browser-repl false
:target :nodejs
:hashbang false
;; :libs [ \"src/cljs/bundled\" \"src/js\" ]
:output-dir ${if simple
then ''\"cljstmp\"''
else ''\"target\"''}
:output-to ${if simple
then ''\"cljstmp/main.js\"''
else ''\"target/deleteme.js\"'' }})
''
);
cacheToJsons = ''
(import [java.io ByteArrayOutputStream FileInputStream])
(require '[cognitect.transit :as transit]
'[clojure.edn :as edn]
'[clojure.string :as str])
cacheToJsons = ''
(import [java.io ByteArrayOutputStream FileInputStream])
(require '[cognitect.transit :as transit]
'[clojure.edn :as edn]
'[clojure.string :as str])
(defn write-transit-json [cache]
(let [out (ByteArrayOutputStream. 1000000)
writer (transit/writer out :json)]
(transit/write writer cache)
(.toString out)))
(defn write-transit-json [cache]
(let [out (ByteArrayOutputStream. 1000000)
writer (transit/writer out :json)]
(transit/write writer cache)
(.toString out)))
(defn process-caches []
(let [cache-aot-path \"target/cljs/core.cljs.cache.aot.edn\"
cache-aot-edn (edn/read-string (slurp cache-aot-path))
cache-macros-path \"target/cljs/core\$macros.cljc.cache.json\"
cache-macros-stream (FileInputStream. cache-macros-path)
cache-macros-edn (transit/read (transit/reader cache-macros-stream :json))
caches [[cache-aot-path cache-aot-edn]
[cache-macros-path cache-macros-edn]]]
(doseq [[path cache-edn] caches]
(doseq [key (keys cache-edn)]
(let [out-path (str/replace path #\"(\.json|\.edn)\$\"
(str \".\" (munge key) \".json\"))
tr-json (write-transit-json (key cache-edn))]
(spit out-path tr-json))))))
(defn process-caches []
(let [cache-aot-path \"target/cljs/core.cljs.cache.aot.edn\"
cache-aot-edn (edn/read-string (slurp cache-aot-path))
cache-macros-path \"target/cljs/core\$macros.cljc.cache.json\"
cache-macros-stream (FileInputStream. cache-macros-path)
cache-macros-edn (transit/read (transit/reader cache-macros-stream :json))
caches [[cache-aot-path cache-aot-edn]
[cache-macros-path cache-macros-edn]]]
(doseq [[path cache-edn] caches]
(doseq [key (keys cache-edn)]
(let [out-path (str/replace path #\"(\.json|\.edn)\$\"
(str \".\" (munge key) \".json\"))
tr-json (write-transit-json (key cache-edn))]
(spit out-path tr-json))))))
(process-caches)
'';
(process-caches)
'';
trimMainJsEnd = ''
(let [string (slurp \"target/main.js\")]
(spit \"target/main.js\"
(subs string 0 (.indexOf string \"cljs.nodejs={};\"))))
'';
trimMainJsEnd = ''
(let [string (slurp \"target/main.js\")]
(spit \"target/main.js\"
(subs string 0 (.indexOf string \"cljs.nodejs={};\"))))
'';
cljdeps = import ./deps.nix { inherit pkgs; };
classp = cljdeps.makeClasspaths {
extraClasspaths=["src/js" "src/cljs/bundled" "src/cljs/snapshot"];
};
getJarPath = jarName: (lib.findFirst (p: p.name == jarName) null cljdeps.packages).path.jar;
in stdenv.mkDerivation {
inherit version;
pname = "lumo";
src = fetchurl {
url = "https://github.com/anmonteiro/lumo/archive/${version}.tar.gz";
sha256 = "1mr3zjslznhv7y3mzvg1pmmvzn10d6di26izz4x8p4nfnshacwgw";
cljdeps = import ./deps.nix { inherit pkgs; };
classp = cljdeps.makeClasspaths {
extraClasspaths = [ "src/js" "src/cljs/bundled" "src/cljs/snapshot" ];
};
buildInputs = [ nodejs clojure jre unzip python openssl
nodePackages."lumo-build-deps-../interpreters/clojurescript/lumo" ];
getJarPath = jarName: (lib.findFirst (p: p.name == jarName) null cljdeps.packages).path.jar;
in
stdenv.mkDerivation {
inherit version;
pname = "lumo";
src = fetchgit {
url = "https://github.com/anmonteiro/lumo.git";
rev = "${version}";
sha256 = "12agi6bacqic2wq6q3l28283badzamspajmajzqm7fbdl2aq1a4p";
};
buildInputs = [
nodejs
clojure
jre
unzip
python
openssl
gnutar
nodePackages."lumo-build-deps-../interpreters/clojurescript/lumo"
]
++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [
ApplicationServices
xcbuild
]
);
patches = [ ./no_mangle.patch ./mkdir_promise.patch ];
postPatch = ''
substituteInPlace $NIX_BUILD_TOP/lumo/vendor/nexe/exe.js \
--replace 'glob.sync(dir + "/*")' 'glob.sync(dir + "/../*")'
'';
buildPhase = ''
# Copy over lumo-build-deps environment
# Copy over lumo-build-deps environment
rm yarn.lock
cp -rf ${nodePackages."lumo-build-deps-../interpreters/clojurescript/lumo"}/lib/node_modules/lumo-build-deps/* ./
# configure clojure-cli
mkdir ./.cpcache
export CLJ_CONFIG=`pwd`
export CLJ_CACHE=`pwd`/.cpcache
export CLJ_CACHE=`pwd`/.cpcache
# require more namespaces for cljs-bundle
sed -i "s!ns lumo.core! \
@@ -155,7 +188,7 @@ in stdenv.mkDerivation {
(:require ${requireDeps}) \
(:require-macros [clojure.template :as temp] \
[cljs.test :as test])!g" \
./src/cljs/snapshot/lumo/core.cljs
./src/cljs/snapshot/lumo/core.cljs
# Step 1: compile clojurescript with :none and :simple
${clojure}/bin/clojure -Scp ${classp} -e "${compileClojurescript true}"
@@ -204,10 +237,13 @@ in stdenv.mkDerivation {
# Step 3: generate munged cache jsons
${clojure}/bin/clojure -Scp ${classp} -e "${cacheToJsons}"
rm ./target/cljs/core\$macros\.cljc\.cache\.json
# Step 4: Bunde javascript
echo 1111
cat scripts/bundle.js
NODE_ENV=production node scripts/bundle.js
echo 2222
node scripts/bundleForeign.js
# Step 5: Backup resources
@@ -215,21 +251,20 @@ in stdenv.mkDerivation {
# Step 6: Package executeable 1st time
# fetch node sources and copy to palce that nexe will find
mkdir -p tmp/${nodeVersion}
cp ${nodeSources} tmp/${nodeVersion}/node-${nodeVersion}.tar.gz
tar -C ./tmp/${nodeVersion} -xf ${nodeSources}
mv ./tmp/${nodeVersion}/node-v${nodeVersion}/* ./tmp/${nodeVersion}/
mkdir -p tmp/node/${nodeVersion}
cp ${nodeSources} tmp/node/${nodeVersion}/node-${nodeVersion}.tar.gz
tar -C ./tmp/node/${nodeVersion} -xf ${nodeSources} --warning=no-unknown-keyword
mv ./tmp/node/${nodeVersion}/node-v${nodeVersion}/* ./tmp/node/${nodeVersion}/
rm -rf ${lumo-internal-classpath}
mv target ${lumo-internal-classpath}
cp -rf target ${lumo-internal-classpath}
node scripts/package.js ${nodeVersion}
rm -rf ${lumo-internal-classpath}
rm -rf target
mv ${lumo-internal-classpath} target
# Step 7: AOT Macros
sh scripts/aot-bundle-macros.sh
# Step 8: Package executeable 2nd time
rm -rf ${lumo-internal-classpath}
mv target ${lumo-internal-classpath}
node scripts/package.js ${nodeVersion}
'';
@@ -250,7 +285,6 @@ in stdenv.mkDerivation {
homepage = https://github.com/anmonteiro/lumo;
license = stdenv.lib.licenses.epl10;
maintainers = [ stdenv.lib.maintainers.hlolli ];
platforms = stdenv.lib.platforms.linux;
platforms = stdenv.lib.platforms.linux ++ stdenv.lib.platforms.darwin;
};
}