Skip to content

Commit

Permalink
nix: use jsbundle derivation for iOS as well
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Jakub Sokołowski <[email protected]>
  • Loading branch information
jakubgs committed May 17, 2023
1 parent 1a8f0ad commit ee82820
Show file tree
Hide file tree
Showing 19 changed files with 46 additions and 48 deletions.
22 changes: 9 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -220,21 +220,17 @@ 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 && \
$(MAKE) jsbundle && \
xcodebuild -workspace ios/StatusIm.xcworkspace -scheme StatusIm -configuration Release -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: ##@jsbundle Compile JavaScript and Clojurescript to create index.js and app.
nix/scripts/build.sh targets.mobile.jsbundle

# Support for legacy naming
jsbundle-ios: jsbundle
jsbundle-android: jsbundle

#--------------
# status-go lib
Expand Down
2 changes: 1 addition & 1 deletion ci/Jenkinsfile.android
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library 'status-jenkins-lib@ios/fix-alchemy-vars'
library 'status-jenkins-lib@ios/nix-built-jsbundle'

/* Options section can't access functions in objects. */
def isPRBuild = utils.isPRBuild()
Expand Down
2 changes: 1 addition & 1 deletion ci/Jenkinsfile.combined
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library 'status-jenkins-lib@ios/fix-alchemy-vars'
library 'status-jenkins-lib@ios/nix-built-jsbundle'

pipeline {
agent { label 'linux' }
Expand Down
2 changes: 1 addition & 1 deletion ci/Jenkinsfile.ios
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library 'status-jenkins-lib@ios/fix-alchemy-vars'
library 'status-jenkins-lib@ios/nix-built-jsbundle'

/* Options section can't access functions in objects. */
def isPRBuild = utils.isPRBuild()
Expand Down
2 changes: 1 addition & 1 deletion ci/Jenkinsfile.nix-cache
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library 'status-jenkins-lib@ios/fix-alchemy-vars'
library 'status-jenkins-lib@ios/nix-built-jsbundle'

pipeline {
agent { label params.AGENT_LABEL }
Expand Down
2 changes: 1 addition & 1 deletion ci/Jenkinsfile.tests
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library 'status-jenkins-lib@ios/fix-alchemy-vars'
library 'status-jenkins-lib@ios/nix-built-jsbundle'

/* Options section can't access functions in objects. */
def isPRBuild = utils.isPRBuild()
Expand Down
2 changes: 1 addition & 1 deletion ci/tests/Jenkinsfile.e2e-nightly
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library 'status-jenkins-lib@ios/fix-alchemy-vars'
library 'status-jenkins-lib@ios/nix-built-jsbundle'

pipeline {

Expand Down
2 changes: 1 addition & 1 deletion ci/tests/Jenkinsfile.e2e-prs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library 'status-jenkins-lib@ios/fix-alchemy-vars'
library 'status-jenkins-lib@ios/nix-built-jsbundle'

pipeline {

Expand Down
2 changes: 1 addition & 1 deletion ci/tests/Jenkinsfile.e2e-upgrade
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library 'status-jenkins-lib@ios/fix-alchemy-vars'
library 'status-jenkins-lib@ios/nix-built-jsbundle'

pipeline {

Expand Down
2 changes: 1 addition & 1 deletion ci/tools/Jenkinsfile.fastlane-clean
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library 'status-jenkins-lib@ios/fix-alchemy-vars'
library 'status-jenkins-lib@ios/nix-built-jsbundle'

pipeline {
agent { label 'macos' }
Expand Down
2 changes: 1 addition & 1 deletion ci/tools/Jenkinsfile.playstore-meta
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library 'status-jenkins-lib@ios/fix-alchemy-vars'
library 'status-jenkins-lib@ios/nix-built-jsbundle'

pipeline {
agent { label 'linux' }
Expand Down
2 changes: 1 addition & 1 deletion ci/tools/Jenkinsfile.xcode-clean
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library 'status-jenkins-lib@ios/fix-alchemy-vars'
library 'status-jenkins-lib@ios/nix-built-jsbundle'

pipeline {
agent {
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import "node-libs-react-native/globals";
import "./app/index.js";
import "./result/index.js";
10 changes: 5 additions & 5 deletions nix/DETAILS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 5 additions & 9 deletions nix/mobile/android/default.nix
Original file line number Diff line number Diff line change
@@ -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; [
Expand Down
8 changes: 5 additions & 3 deletions nix/mobile/android/release.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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"
];
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion nix/mobile/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
let
fastlane = callPackage ./fastlane { };

jsbundle = callPackage ./jsbundle { };

android = callPackage ./android {
inherit jsbundle;
status-go = status-go.mobile.android;
};

Expand All @@ -26,5 +29,5 @@ in {
};

# TARGETS
inherit android ios fastlane;
inherit android ios fastlane jsbundle;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -77,6 +77,6 @@ stdenv.mkDerivation {
'';
installPhase = ''
mkdir -p $out
cp -r index.js app $out/
cp -r result/* $out/
'';
}
3 changes: 2 additions & 1 deletion shadow-cljs.edn
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ee82820

Please sign in to comment.