Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mobile builds #1108

Draft
wants to merge 6 commits into
base: haskell.nix
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions all-builds.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
}
, local-self ? import ./. self-args
, supportedSystems ? [ builtins.currentSystem ]
, __useNewerCompiler ? true # false if one wants to use ghc 8.6.5
}:

let
Expand Down Expand Up @@ -41,8 +40,21 @@ let
else if lib.isList v then lib.concatMap collect v
else [];

# A simple derivation that just creates a file with the names of all
# of its inputs. If built, it will have a runtime dependency on all
# of the given build inputs.
pinBuildInputs = name: buildInputs: (local-self.nixpkgs.releaseTools.aggregate {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was removed from reflex-platform. Not sure if intentional

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I wasn't needing them while doing the haskell.nix work. I don't think we need them in reflex-platform anymore but pulling it into the obelisk nix is fine by me

inherit name;
constituents = buildInputs;
}).overrideAttrs (old: {
buildCommand = old.buildCommand + ''
echo "$propagatedBuildInputs $buildInputs $nativeBuildInputs $propagatedNativeBuildInputs" > "$out/deps"
'';
inherit buildInputs;
});

perPlatform = lib.genAttrs cacheBuildSystems (system: let
reflex-platform = import ./dep/mars { inherit system __useNewerCompiler; };
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gives me eval errors

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you could post those errors that'd be great!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reflex-platform = import ./dep/mars { inherit system; };

mkPerProfiling = profiling: let
obelisk = import ./. (self-args // { inherit system profiling; });
Expand All @@ -69,8 +81,6 @@ let
echo "return" >> "$out"
cat "${skeleton.shells.ghc}" >> "$out"
'';
androidSkeleton = skeleton.android.frontend;
iosSkeleton = skeleton.ios.frontend;
nameSuffix = if profiling then "profiled" else "unprofiled";
packages = {
skeletonProfiledObRun = rawSkeleton.__unstable__.profiledObRun;
Expand All @@ -84,13 +94,13 @@ let
ghcjs
serverSkeletonExe
;
} // lib.optionalAttrs reflex-platform.androidSupport {
inherit androidSkeleton;
} // lib.optionalAttrs reflex-platform.iosSupport {
inherit iosSkeleton;
} // lib.optionalAttrs (system == "x86_64-linux") {
android-app = rawSkeleton.android.app.aarch64;
} // lib.optionalAttrs (system == "x86_64-darwin") {
Copy link
Collaborator Author

@alexfmpe alexfmpe Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

androidSupport/iosSupport are gone:
https://github.com/reflex-frp/reflex-platform/blob/20a0a01ec32a747106cb22605832cb57f6fb62ca/default.nix#L106-L107

For now I mirrored what's in
https://github.com/reflex-frp/reflex-platform/blob/20a0a01ec32a747106cb22605832cb57f6fb62ca/release.nix#L15-L20
but it's strange that the logic for whether a platform is supported be pushed on users

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm the ghcShell failure on darwin is interesting, I think we'll be okay disabling it (for now at least) but maybe we should be disabling webkit2gtk for darwin..

ios-app = rawSkeleton.ios.app.aarch64;
};
in packages // {
cache = reflex-platform.pinBuildInputs
cache = pinBuildInputs
"obelisk-${system}-${nameSuffix}"
(collect packages);
};
Expand All @@ -100,12 +110,12 @@ let
unprofiled = mkPerProfiling false;
};
in perProfiling // {
cache = reflex-platform.pinBuildInputs
cache = pinBuildInputs
"obelisk-${system}"
(map (p: p.cache) (builtins.attrValues perProfiling));
});

metaCache = local-self.reflex-platform.pinBuildInputs
metaCache = pinBuildInputs
"obelisk-everywhere"
(map (a: a.cache) (builtins.attrValues perPlatform));

Expand Down
2 changes: 0 additions & 2 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,6 @@ in rec {
#(hackage: (import "${marsObelisk.plan-nix}/default.nix").pkgs hackage)
];

ghcjs-app = self.crossSystems.ghcjs.hsPkgs.frontend.components.exes.frontend;

userSettings = {
android = reflexHasAttr "android";
ios = reflexHasAttr "ios";
Expand Down
4 changes: 2 additions & 2 deletions dep/mars/github.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"repo": "reflex-platform",
"branch": "haskell.nix",
"private": false,
"rev": "d5f1a1eb2ab91faa2fdb162085c40e417b0e5afe",
"sha256": "1vb69xjlb0c0f0hbrvbhw9na392sl7nn464d3kinpbjdyd9kdw6n"
"rev": "4fccfb196ac724695a5006a456b2125eeff331e5",
"sha256": "0f383z3pzcdnwv0ijbbm6xiky3k0lw31dx03x3nrpv46n929nh68"
}
21 changes: 20 additions & 1 deletion release.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
{ supportedSystems ? [ "x86_64-linux" "aarch64-darwin" "x86_64-darwin" ]
{ supportedSystems ? [ "x86_64-linux" "x86_64-darwin" ]
}:
let
obelisk = import ./. {};
pkgs = obelisk.nixpkgs;
recurse = x: x // { recurseForDerivations = true; };
in
recurse (pkgs.lib.genAttrs supportedSystems (system:
let
skeleton = import ./skeleton { inherit system; };
in with skeleton; recurse ({
inherit exe;
inherit (obelisk.marsObelisk.hsPkgs) obelisk-selftest;
} // pkgs.lib.optionalAttrs (system == "x86_64-linux") {
android-app = recurse android.app;
} // pkgs.lib.optionalAttrs (system == "x86_64-darwin") {
ios-app = recurse ios.app;
})))

/*
rec {
recurseForDerivations = true;
build = import ./all-builds.nix { inherit supportedSystems; };
test = import ./all-tests.nix { inherit supportedSystems; };
inherit (build) metaCache;
}
*/
57 changes: 53 additions & 4 deletions skeleton/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,72 @@
}
}:
with obelisk;
project {} ({ pkgs, ... }: {
let args = {
# You must accept the Android Software Development Kit License Agreement at
# https://developer.android.com/studio/terms in order to build Android apps.
# Uncomment this to indicate your acceptance:
android_sdk_accept_license = true;
allowUnfree = true;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be set to false before merging.
How do we make sure CI caches it though?
Add the accept/allow as args to this file defaulting to false and overriden by CI?

}; in

project args ({ pkgs, ... }: {
name = "skeleton";
android = {
executable = ps: exes: (exes (ps.frontend)).frontend;
executableName = "obelisk-skeleton";
applicationId = "systems.obsidian.obelisk.examples.minimal";
displayName = "Obelisk Minimal Example";
};
ios = {
executable = ps: exes: (exes (ps.frontend)).frontend;
executableName = "obelisk-skeleton";
bundleIdentifier = "systems.obsidian.obelisk.examples.minimal";
bundleName = "Obelisk Minimal Example";
};
web = {
executable = ps: exes: (exes (ps.frontend)).frontend;
};
extraArgs = {
staticFiles = ./static;
};
src = ./.;
inputThunks = pkgs.obsidianCompilers.thunkSets.common ++ [
pkgs._dep.source.aeson-1541
pkgs._dep.source.android-activity
cidkidnix marked this conversation as resolved.
Show resolved Hide resolved
];
shells = ps: with ps; [
backend
];
overrides = [
({ config, pkgs, lib, ... }: {
config.enableShared = if pkgs.stdenv.targetPlatform.isiOS then lib.mkForce false else true;
config.enableStatic = lib.mkForce true;
})
({pkgs, lib, config, ... }: {
packages.obelisk-run.components.library.build-tools = with pkgs; [
iproute
];
packages.obelisk-run.components.library.build-tools = with pkgs; [
iproute
];

packages.reflex-dom = {
flags = {
webkit2gtk = if (pkgs.stdenv.targetPlatform.isAndroid) then lib.mkForce false else true;
};
};

packages.frontend.components.exes.frontend = {
frameworks = if (!pkgs.stdenv.targetPlatform.isiOS && pkgs.stdenv.targetPlatform.isDarwin) then [ pkgs.darwin.apple_sdk.frameworks.CoreFoundation ] else [ ];
postInstall = lib.optionalString (pkgs.stdenv.hostPlatform.isDarwin) ''
mkdir -p $out/obelisk-skeleton.app
cp -r obelisk-skeleton $out
cp $out/bin/obelisk-skeleton $out/obelisk-skeleton.app
'';
};
packages.jsaddle-wkwebview.src = (thunkSource ../dep/jsaddle) + "/jsaddle-wkwebview";
packages.jsaddle-wkwebview.components.library = {
frameworks =
if (pkgs.stdenv.targetPlatform.isiOS) then lib.mkForce [ pkgs.darwin.iosSdkPkgs.sdk pkgs.darwin.apple_sdk.frameworks.CoreFoundation ]
else [ pkgs.darwin.apple_sdk.frameworks.CoreFoundation ];
};
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was getting webkit2gtk eval failures on android so cargo-culted this section from https://github.com/reflex-frp/reflex-platform/blob/4fccfb196ac724695a5006a456b2125eeff331e5/example/default.nix#L62

We definitely don't want this re-done on every project.
Something more like, shoved into a trivially importable overlay on reflex-platform?
Could maybe have it implicitly applied by obelisk, but then what happens on module conflicts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the linked code should always be applied in obelisk (not so much in reflex-platform). If folks need to overwrite it they can use "lib.mkOverride" for a higher value than "lib.mkForce". I'd much rather this be a default instead of some documentation or comments anywhere

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well yes but a default on obelisk or on the obelisk skeleton?

})
];
})