From 58d20967ae1068b8e6eee7448f04083a502f4c0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Tue, 16 May 2023 18:42:56 +0200 Subject: [PATCH] nix: use jsbundle derivation for iOS as well MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For some unknown to me reason we are using a different Yarn call to Shadow-cljs to generate the JSBundle for iOS builds, while the one created by the Android derivation shoudl be exactly the same. I'm changing the target to just be `make jsbundle` while keeping aliases referencing old naming, and moving things around in `nix` folder to reflect the fact that the derivation is no longer Android-specific. Also, crucially, I've changed the `import` in `index.js` to use the `./result/index.js` path, since that's what Nix creates. I'm not sure if this clashes with any developer workflow that takes place locally, so I'd appreciate some testing from developers. Depends on: https://github.com/status-im/status-jenkins-lib/pull/67 Signed-off-by: Jakub SokoĊ‚owski --- Makefile | 32 +++++++++---------- ci/Jenkinsfile.android | 2 +- ci/Jenkinsfile.combined | 2 +- ci/Jenkinsfile.ios | 2 +- ci/Jenkinsfile.nix-cache | 2 +- ci/Jenkinsfile.tests | 2 +- ci/tests/Jenkinsfile.e2e-nightly | 2 +- ci/tests/Jenkinsfile.e2e-prs | 2 +- ci/tests/Jenkinsfile.e2e-upgrade | 2 +- ci/tools/Jenkinsfile.fastlane-clean | 2 +- ci/tools/Jenkinsfile.playstore-meta | 2 +- ci/tools/Jenkinsfile.xcode-clean | 2 +- index.js | 2 +- nix/DETAILS.md | 10 +++--- nix/mobile/android/default.nix | 14 +++----- nix/mobile/android/release.nix | 8 +++-- nix/mobile/default.nix | 5 ++- nix/mobile/{android => }/jsbundle/default.nix | 8 ++--- shadow-cljs.edn | 3 +- 19 files changed, 53 insertions(+), 51 deletions(-) rename nix/mobile/{android => }/jsbundle/default.nix (94%) diff --git a/Makefile b/Makefile index 7cf81f894f..3ce599af4f 100644 --- a/Makefile +++ b/Makefile @@ -218,23 +218,18 @@ release-android: keystore build-android ##@build Build signed Android APK release-ios: export TARGET := ios release-ios: export BUILD_ENV ?= prod -release-ios: watchman-clean ##@build Build release for iOS release - @git clean -dxf -f target/ios && \ - $(MAKE) jsbundle-ios && \ - xcodebuild -workspace ios/StatusIm.xcworkspace -scheme StatusIm -configuration Release -destination 'generic/platform=iOS' -UseModernBuildSystem=N clean archive +release-ios: watchman-clean ios-clean jsbundle ##@build Build release for iOS release + xcodebuild \ + -scheme StatusIm \ + -configuration Release \ + -workspace ios/StatusIm.xcworkspace \ + -destination 'generic/platform=iOS' \ + -UseModernBuildSystem=N clean archive -jsbundle-android: SHELL := /bin/sh -jsbundle-android: export TARGET := android -jsbundle-android: export BUILD_ENV ?= prod -jsbundle-android: ##@jsbundle Compile JavaScript and Clojurescript into app directory - # Call nix-build to build the 'targets.mobile.android.jsbundle' attribute and copy the.js files to the project root - nix/scripts/build.sh targets.mobile.android.jsbundle && \ - mv result/*.js ./ - -jsbundle-ios: export TARGET := ios -jsbundle-ios: export BUILD_ENV ?= prod -jsbundle-ios: ##@jsbundle Compile JavaScript and Clojure into index.ios.js - yarn shadow-cljs release mobile +jsbundle: SHELL := /bin/sh +jsbundle: export BUILD_ENV ?= prod +jsbundle: ##@build Build JavaScript and Clojurescript bundle for iOS and Android + nix/scripts/build.sh targets.mobile.jsbundle #-------------- # status-go lib @@ -365,6 +360,7 @@ component-test: ##@test Run component tests once in NodeJS yarn shadow-cljs compile component-test && \ jest --config=test/jest/jest.config.js +#-------------- # Other #-------------- @@ -373,6 +369,10 @@ geth-connect: ##@other Connect to Geth on the device adb forward tcp:8545 tcp:8545 && \ build/bin/geth attach http://localhost:8545 +ios-clean: SHELL := /bin/sh +ios-clean: ##@prepare Clean iOS build artifacts + git clean -dxf -f target/ios + android-clean: export TARGET := gradle android-clean: ##@prepare Clean Gradle state git clean -dxf -f ./android/app/build; \ diff --git a/ci/Jenkinsfile.android b/ci/Jenkinsfile.android index 5e1f25998c..fdd647c5c0 100644 --- a/ci/Jenkinsfile.android +++ b/ci/Jenkinsfile.android @@ -1,4 +1,4 @@ -library 'status-jenkins-lib@v1.7.6' +library 'status-jenkins-lib@v1.7.7' /* Options section can't access functions in objects. */ def isPRBuild = utils.isPRBuild() diff --git a/ci/Jenkinsfile.combined b/ci/Jenkinsfile.combined index bc26fc73c7..ddfc7e629f 100644 --- a/ci/Jenkinsfile.combined +++ b/ci/Jenkinsfile.combined @@ -1,4 +1,4 @@ -library 'status-jenkins-lib@v1.7.6' +library 'status-jenkins-lib@v1.7.7' pipeline { agent { label 'linux' } diff --git a/ci/Jenkinsfile.ios b/ci/Jenkinsfile.ios index 46ca87a88e..0e2a081b51 100644 --- a/ci/Jenkinsfile.ios +++ b/ci/Jenkinsfile.ios @@ -1,4 +1,4 @@ -library 'status-jenkins-lib@v1.7.6' +library 'status-jenkins-lib@v1.7.7' /* Options section can't access functions in objects. */ def isPRBuild = utils.isPRBuild() diff --git a/ci/Jenkinsfile.nix-cache b/ci/Jenkinsfile.nix-cache index ece4124250..79edad6ed7 100644 --- a/ci/Jenkinsfile.nix-cache +++ b/ci/Jenkinsfile.nix-cache @@ -1,4 +1,4 @@ -library 'status-jenkins-lib@v1.7.6' +library 'status-jenkins-lib@v1.7.7' pipeline { agent { label params.AGENT_LABEL } diff --git a/ci/Jenkinsfile.tests b/ci/Jenkinsfile.tests index 8979bc2e40..a1745e0047 100644 --- a/ci/Jenkinsfile.tests +++ b/ci/Jenkinsfile.tests @@ -1,4 +1,4 @@ -library 'status-jenkins-lib@v1.7.6' +library 'status-jenkins-lib@v1.7.7' /* Options section can't access functions in objects. */ def isPRBuild = utils.isPRBuild() diff --git a/ci/tests/Jenkinsfile.e2e-nightly b/ci/tests/Jenkinsfile.e2e-nightly index d0198aef50..aa5ee39341 100644 --- a/ci/tests/Jenkinsfile.e2e-nightly +++ b/ci/tests/Jenkinsfile.e2e-nightly @@ -1,4 +1,4 @@ -library 'status-jenkins-lib@v1.7.6' +library 'status-jenkins-lib@v1.7.7' pipeline { diff --git a/ci/tests/Jenkinsfile.e2e-prs b/ci/tests/Jenkinsfile.e2e-prs index 96b46788b8..22c321125e 100644 --- a/ci/tests/Jenkinsfile.e2e-prs +++ b/ci/tests/Jenkinsfile.e2e-prs @@ -1,4 +1,4 @@ -library 'status-jenkins-lib@v1.7.6' +library 'status-jenkins-lib@v1.7.7' pipeline { diff --git a/ci/tests/Jenkinsfile.e2e-upgrade b/ci/tests/Jenkinsfile.e2e-upgrade index 48154b0946..79411b3342 100644 --- a/ci/tests/Jenkinsfile.e2e-upgrade +++ b/ci/tests/Jenkinsfile.e2e-upgrade @@ -1,4 +1,4 @@ -library 'status-jenkins-lib@v1.7.6' +library 'status-jenkins-lib@v1.7.7' pipeline { diff --git a/ci/tools/Jenkinsfile.fastlane-clean b/ci/tools/Jenkinsfile.fastlane-clean index 02620b5999..1b782c350c 100644 --- a/ci/tools/Jenkinsfile.fastlane-clean +++ b/ci/tools/Jenkinsfile.fastlane-clean @@ -1,4 +1,4 @@ -library 'status-jenkins-lib@v1.7.6' +library 'status-jenkins-lib@v1.7.7' pipeline { agent { label 'macos' } diff --git a/ci/tools/Jenkinsfile.playstore-meta b/ci/tools/Jenkinsfile.playstore-meta index 39dabb3527..a79ccd1791 100644 --- a/ci/tools/Jenkinsfile.playstore-meta +++ b/ci/tools/Jenkinsfile.playstore-meta @@ -1,4 +1,4 @@ -library 'status-jenkins-lib@v1.7.6' +library 'status-jenkins-lib@v1.7.7' pipeline { agent { label 'linux' } diff --git a/ci/tools/Jenkinsfile.xcode-clean b/ci/tools/Jenkinsfile.xcode-clean index a11416be34..052c4ed16e 100644 --- a/ci/tools/Jenkinsfile.xcode-clean +++ b/ci/tools/Jenkinsfile.xcode-clean @@ -1,4 +1,4 @@ -library 'status-jenkins-lib@v1.7.6' +library 'status-jenkins-lib@v1.7.7' pipeline { agent { diff --git a/index.js b/index.js index e00193dcc8..fc718b7182 100644 --- a/index.js +++ b/index.js @@ -1,2 +1,2 @@ import "node-libs-react-native/globals"; -import "./app/index.js"; +import "./result/index.js"; diff --git a/nix/DETAILS.md b/nix/DETAILS.md index e997c86dfc..52914c023b 100644 --- a/nix/DETAILS.md +++ b/nix/DETAILS.md @@ -55,12 +55,12 @@ The [`nix/scripts/shell.sh`](./scripts/shell.sh) script is essentially a wrapper # Building -We will use the `make jsbundle-android` target as an example of a derivation you can build using Nix: +We will use the `make jsbundle` target as an example of a derivation you can build using Nix: -1. `make jsbundle-android` is called by developer -2. `make` calls `nix/scripts/build.sh targets.mobile.android.jsbundle` -3. [`build.sh`](/nix/scripts/build.sh) calls `nix-build --attr targets.mobile.android.jsbundle` with extra arguments -4. `nix-build` builds the derivation from [`nix/mobile/android/jsbundle/default.nix`](/nix/mobile/android/jsbundle/default.nix) +1. `make jsbundle` is called by developer +2. `make` calls `nix/scripts/build.sh targets.mobile.jsbundle` +3. [`build.sh`](/nix/scripts/build.sh) calls `nix-build --attr targets.mobile.jsbundle` with extra arguments +4. `nix-build` builds the derivation from [`nix/mobile/jsbundle/default.nix`](/nix/mobile/jsbundle/default.nix) The same can be done for other targets like `targets.mobile.android.release`. Except in that case extra arguments are required which is why the [`scripts/release-android.sh`](/scripts/release-android.sh) is used in the `make release-android` target. diff --git a/nix/mobile/android/default.nix b/nix/mobile/android/default.nix index a7ec8e805b..d069737044 100644 --- a/nix/mobile/android/default.nix +++ b/nix/mobile/android/default.nix @@ -1,14 +1,10 @@ { pkgs, deps, callPackage, mkShell -, status-go, androidPkgs, androidShell }: +, jsbundle, status-go, androidPkgs, androidShell }: -let - # Import a jsbundle compiled out of clojure codebase - jsbundle = callPackage ./jsbundle { }; - - release = callPackage ./release.nix { inherit jsbundle status-go; }; -in { - # TARGETS - inherit release jsbundle; +rec { + release = callPackage ./release.nix { + inherit jsbundle status-go; + }; shell = mkShell { buildInputs = with pkgs; [ diff --git a/nix/mobile/android/release.nix b/nix/mobile/android/release.nix index 392eada1e3..aabd5d734e 100644 --- a/nix/mobile/android/release.nix +++ b/nix/mobile/android/release.nix @@ -46,7 +46,7 @@ in stdenv.mkDerivation rec { root = path; include = [ "package.json" "yarn.lock" "metro.config.js" "babel.config.js" - "resources/.*" "translations/.*" "src/js/.*" + "resources/.*" "translations/.*" "src/js/.*" "index.js" "modules/react-native-status/android.*" "android/.*" envFileName "VERSION" "status-go-version.json" "react-native.config.js" ]; @@ -94,8 +94,10 @@ in stdenv.mkDerivation rec { # Export all vars from .env file export $(cut -d= -f1 .env) - # Copy index.js and app/ input files - cp -ra --no-preserve=ownership ${builtJsBundle}/* ./ + # Symlink React Native entrypoint. + cp -Lr ${builtJsBundle} ./result + pwd + find -L result # Copy android/ directory mkdir -p ./android/build diff --git a/nix/mobile/default.nix b/nix/mobile/default.nix index 470a3378a8..7c7784132e 100644 --- a/nix/mobile/default.nix +++ b/nix/mobile/default.nix @@ -3,7 +3,10 @@ let fastlane = callPackage ./fastlane { }; + jsbundle = callPackage ./jsbundle { }; + android = callPackage ./android { + inherit jsbundle; status-go = status-go.mobile.android; }; @@ -26,5 +29,5 @@ in { }; # TARGETS - inherit android ios fastlane; + inherit android ios fastlane jsbundle; } diff --git a/nix/mobile/android/jsbundle/default.nix b/nix/mobile/jsbundle/default.nix similarity index 94% rename from nix/mobile/android/jsbundle/default.nix rename to nix/mobile/jsbundle/default.nix index 97fa088896..8b6bb025f1 100644 --- a/nix/mobile/android/jsbundle/default.nix +++ b/nix/mobile/jsbundle/default.nix @@ -8,9 +8,9 @@ { secretsFile ? "" }: stdenv.mkDerivation { - name = "status-mobile-build-jsbundle-android"; + name = "status-mobile-jsbundle"; src = - let path = ./../../../..; + let path = ./../../..; # We use builtins.path so that we can name the resulting derivation, # otherwise the name would be taken from the checkout directory, # which is outside of our control inherit path; @@ -25,7 +25,7 @@ stdenv.mkDerivation { ignoreVCS = false; include = [ "VERSION" "BUILD_NUMBER" "scripts/version/.*" - "src/.*" "shadow-cljs.edn" "index.js" + "src/.*" "shadow-cljs.edn" # I want to avoid including the whole .git directory ".git/HEAD" ".git/objects" ".git/refs/heads/.*" # shadow-cljs expects these for deps resolution @@ -77,6 +77,6 @@ stdenv.mkDerivation { ''; installPhase = '' mkdir -p $out - cp -r index.js app $out/ + cp -r result/* $out/ ''; } diff --git a/shadow-cljs.edn b/shadow-cljs.edn index 7825053262..180f571704 100644 --- a/shadow-cljs.edn +++ b/shadow-cljs.edn @@ -37,7 +37,8 @@ :builds {:mobile {:target :react-native - :output-dir "app" + ;; To match the folder created by Nix build of JSBundle. + :output-dir "result" :init-fn status-im2.core/init ;; When false, the Shadow-CLJS watcher won't automatically refresh ;; the target files (a.k.a hot reload). When false, you can manually