-
-
Notifications
You must be signed in to change notification settings - Fork 15k
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
Add pkgsCross.emscripten, replacing hand-crafted emscriptenPackages #217428
base: staging
Are you sure you want to change the base?
Conversation
What do you think about this approach? @qknight @matthewbauer @RaitoBezarius |
Interesting changes, thank you for doing this. I am not too expert in the stdenv area, so I would rather defer to people working on that, cc @alyssais @Ericson2314 I will need more time to review though and test thoroughly, but it seems to be a PR in the right direction. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very promising direction. Thank you for exploring it! Since it's still early, I've focused my review only on the stdenv stuff, not any individual package modifications.
The biggest threat I see is the split binaries, so some more info on those would be great.
Thanks @alyssais. I'm going to update this branch to use Emscripten's |
Could you please fix the syntax errors in overlay.nix? And maybe update to latest nixpkgs? |
Let's get this after the branch-off :). |
Just as a note for a parallel emscripten change, #229718 (not merged as of this comment) would bump underlying emscripten from 3.1.24 to 3.1.39, which in turn requires LLVM 16 instead of 14. |
lib/systems/parse.nix
Outdated
@@ -294,6 +294,7 @@ rec { | |||
openbsd = { execFormat = elf; families = { inherit bsd; }; }; | |||
solaris = { execFormat = elf; families = { }; }; | |||
wasi = { execFormat = wasm; families = { }; }; | |||
emscripten = { execFormat = wasm; families = { }; }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
emscripten = { execFormat = wasm; families = { }; }; | |
emscripten = { execFormat = wasm; families = { }; }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Best would be to adjust the alignment of the others to match.
, isGNU ? false, isClang ? cc.isClang or false, gnugrep ? null | ||
, isGNU ? false | ||
, isClang ? cc.isClang or false | ||
, isEmscripten ? cc.isEmscripten or false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not used
explicitFlags ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) crossFlags; | ||
explicitFlags | ||
++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) crossFlags | ||
++ (stdenv.extraCmakeFlags or []) ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
++ (stdenv.extraCmakeFlags or []) ; | |
++ (stdenv.extraCmakeFlags or []); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parens aren't necessary either, I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer keeping the parens as it makes it more clear what is meant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would trust deadnix. If it says they are optional, I would remove them.
pkgs/stdenv/emscripten/overlay.nix
Outdated
bullet = bullet; | ||
bzip2 = bzip2; | ||
giflib = giflib; | ||
harfbuzz = harfbuzz; | ||
icu = icu; | ||
libjpeg = libjpeg; | ||
libmodplug = libmodplug; | ||
libpng = libpng; | ||
mpg123 = mpg123; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bullet = bullet; | |
bzip2 = bzip2; | |
giflib = giflib; | |
harfbuzz = harfbuzz; | |
icu = icu; | |
libjpeg = libjpeg; | |
libmodplug = libmodplug; | |
libpng = libpng; | |
mpg123 = mpg123; | |
inherit bullet bzip2 giflib harfbuzz icu libjpeg libmodplug libpng mpg123 zlib; |
pkgs/stdenv/emscripten/overlay.nix
Outdated
libogg = ogg; | ||
sqlite = sqlite3; | ||
libvorbis = vorbis; | ||
zlib = zlib; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zlib = zlib; |
sha256 = "sha256-hzXN30IocklLty8daZSF5rHQJ4xHKLWzCQP7o0m5Z0s="; | ||
}; | ||
libpng = { | ||
url = "https://github.com/libsdl-org/SDL/archive/release-2.24.0.zip"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least this URL is duplicated. Not sure if it is worth to dedupe. Also can't we re-use the src's from our packages?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've fixed the duplicate URLs. The src's from nixpkgs cannot be used here, the url
in this file point to the exact sources that embuilder.py
requires.
buildInputs = [ makeWrapper ]; | ||
|
||
unpackPhase = '' | ||
src=$PWD |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use sourceRoot?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just copied this from pkgs/build-support/bintools-wrapper/default.nix
. How would I use srcRoot
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is okay, the point is to forgo upacking (since there is no source), but src
needs to be set to something. sourceRoot
only controls the working directory which is irrelevant here.
Noting that #229718, which bumps underlying emscripten and llvm, has entered staging. |
lib/systems/default.nix
Outdated
emulatorAvailable = pkgs: (selectEmulator pkgs) != null; | ||
|
||
emulator = pkgs: | ||
emulatorNeeded = pkgs: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused and there's already canExecute
pkgs/top-level/all-packages.nix
Outdated
makeWrapper = | ||
if stdenv.hostPlatform.isWindows || stdenv.hostPlatform.isEmscripten | ||
then null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should throw or something
should break early
comment why it doesn't work on emscripten
can't be changed to makeBinaryWrapper globally on windows #120726 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My intent here is to allow packages to conditionally use makeWrapper
if it is available by checking for makeWrapper == null
. Changing this to a throw wouldn't work for that. Is there a better way to do that? Maybe something like lib.elem stdenv.hostPlatform makeWrapper.meta.platforms
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, the using expression should check whether something is available or not. lib.meta.availableOn
should suffice for this, given that the compatibility is expressed in (makeWrapper
's) meta.platforms
.
Using null
will also break makeWrapper
in buildPackages
for the affected package sets due to splicing depending on attribute sets.
passthru = { | ||
libc_bin = ""; | ||
libc_dev = ""; | ||
libc_lib = ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
null
is better here.
pkgs/top-level/all-packages.nix
Outdated
makeWrapper = | ||
if stdenv.hostPlatform.isWindows || stdenv.hostPlatform.isEmscripten | ||
then null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, the using expression should check whether something is available or not. lib.meta.availableOn
should suffice for this, given that the compatibility is expressed in (makeWrapper
's) meta.platforms
.
Using null
will also break makeWrapper
in buildPackages
for the affected package sets due to splicing depending on attribute sets.
pkgs/top-level/all-packages.nix
Outdated
@@ -7469,10 +7472,6 @@ with pkgs; | |||
|
|||
zzuf = callPackage ../tools/security/zzuf { }; | |||
|
|||
### DEVELOPMENT / EMSCRIPTEN | |||
|
|||
buildEmscriptenPackage = callPackage ../development/em-modules/generic { }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a substantial, breaking change and should also be explained in the release notes for 23.11.
|
||
* nix | ||
* nixpkgs | ||
This mode is far more power full since this makes use of `nix` for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This mode is far more power full since this makes use of `nix` for | |
This mode is far more powerful since this makes use of `nix` for |
Though this sentence doesn't really make sense: More powerful than what? Imperative Usage is only described later on…
lib/systems/default.nix
Outdated
emulatorAvailable = pkgs: (selectEmulator pkgs) != null; | ||
|
||
emulator = pkgs: | ||
emulatorCommand = pkgs: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dislike introducing yet another field here, how is this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CMake variable CMAKE_CROSSCOMPILING_EMULATOR
requires a semicolon-delimited command.
buildInputs = [ makeWrapper ]; | ||
|
||
unpackPhase = '' | ||
src=$PWD |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is okay, the point is to forgo upacking (since there is no source), but src
needs to be set to something. sourceRoot
only controls the working directory which is irrelevant here.
@@ -27,7 +27,9 @@ let | |||
# https://gitlab.gnome.org/GNOME/libxml2/-/commit/b706824b612adb2c8255819c9a55e78b52774a3c | |||
# This case is encountered "temporarily" during stdenv bootstrapping on darwin. | |||
# Beware that the old version has known security issues, so the final set shouldn't use it. | |||
oldVer = python.pname == "python3-minimal"; | |||
oldVer = | |||
(pythonSupport || stdenv.isDarwin) # testing for isDarwin only to avoid mass rebuild (stdenv contains libxml2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just target staging.
@@ -172,7 +174,7 @@ let | |||
mkdir -p $bin | |||
mv $out/bin $bin/bin | |||
|
|||
'' + lib.optionalString (!stdenv.hostPlatform.isWindows) | |||
'' + lib.optionalString (makeWrapper != null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lib.meta.availableOn makeWrapper stdenv.hostPlatform
would be a possibility or querying meta.broken
of makeWrapper
—or just expanding the conditional.
For better or worse, the convention in nixpkgs is that the expression using a package decides whether it can use it or not. This also has the sense that it prevents stuff from being silently unavailable which can alter configure time settings etc.
@@ -380,7 +380,7 @@ else let | |||
"-DCMAKE_HOST_SYSTEM_PROCESSOR=${stdenv.buildPlatform.uname.processor}" | |||
] ++ lib.optionals (stdenv.buildPlatform.uname.release != null) [ | |||
"-DCMAKE_HOST_SYSTEM_VERSION=${stdenv.buildPlatform.uname.release}" | |||
]); | |||
]) ++ (stdenv.extraCmakeFlags or []); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is better achieved with a setup hook that appends to cmakeFlags
.
Thanks for the suggestions. I've:
|
addEnvHooks "$hostOffset" addEmscriptenCMakeEnv | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trailing newlines should be removed
targetPrefix = "${wasmArch}-emscripten-"; | ||
llvm = emscripten.llvmEnv; | ||
|
||
unwrapped = stdenv.mkDerivation { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong indentation, run git diff --name-only HEAD~ --diff-filter=A | grep "\.nix" | xargs nixpkgs-fmt
to format added files only
unpackPhase = '' | ||
src=$PWD | ||
''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unpackPhase = '' | |
src=$PWD | |
''; | |
dontUnpack = true; |
same for the others
src=$PWD | ||
''; | ||
|
||
installPhase = '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
runHook
's missing
also in other files
lnLLVM llvm-cxxfilt c++filt | ||
lnLLVM llvm-addr2line addr2line | ||
|
||
echo -n > $out/nix-support/libc-ldflags-before |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?, add a comment.
pkgs/top-level/all-packages.nix
Outdated
@@ -21135,6 +21138,7 @@ with pkgs; | |||
else if name == "nblibc" then targetPackages.netbsdCross.libc or netbsdCross.libc | |||
else if name == "wasilibc" then targetPackages.wasilibc or wasilibc | |||
else if name == "relibc" then targetPackages.relibc or relibc | |||
else if stdenv.targetPlatform.isEmscripten then null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is emscripten special from all the others, why is stdenv.targetPlatform.libc
not null on emscripten
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll remove this and set libc = null
@@ -136,7 +136,7 @@ stdenv.mkDerivation rec { | |||
''; | |||
license = licenses.gpl3Plus; | |||
platforms = platforms.all; | |||
maintainers = with maintainers; [ dtzWill ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
accidentally removed
lib/tests/systems.nix
Outdated
@@ -95,6 +95,7 @@ lib.runTests ( | |||
# The functions should be derived from the data, so this is not a problem. | |||
canExecute = null; | |||
emulator = null; | |||
emulatorCommand = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
emulatorCommand = null; |
leftover
@@ -125,3 +125,5 @@ The module update takes care of the new config syntax and the data itself (user | |||
./common/auto-format-root-device.nix ];` When you use the systemd initrd, you | |||
can automatically format the root device by setting | |||
`virtualisation.fileSystems."/".autoFormat = true;`. | |||
|
|||
- `emscriptenPackages` and `buildEmscriptenPackage` have been replaced with `pkgsCross.emscripten` and `pkgsCross.emscripten.stdenv.mkDerivation`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't add directly at the end but at a random location to prevent merge conflicts
As a quick note I've discovered working through #260267 -- emscripten will now need access to emscripten's node_modules folder as well, so it can run |
I was experimenting a bit with this PR and considering to revive it and noticed that the following works:
However, this does not work:
Instead it fails with the error, "Unknown libc emscripten". Is this expected? |
Description of changes
SYSTEM
cache to theemscripten
packageemscriptenFull
which additionally contains EmscriptenPORTS
emscriptenNoCache
which requires settingEM_CACHE
to useemscriptenCC
andemscriptenBintools
lib/systems
andpkgsCross
xmlmirror
package from insidetop-level/emscripten-packages.nix
totools/text/xml
emscriptenPackages.json_c
andemscriptenPackages.zlib
buildEmscriptenPackage
pkgsCross.emscripten
packages torelease-cross.nix
Possibly fixes #28929 #141246 #136396. Improves the fix for #139943.
Tested with
Things done
sandbox = true
set innix.conf
? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)