From c26fd684d13ef9df85b059c47f9c1f2883211db8 Mon Sep 17 00:00:00 2001 From: Mio Date: Mon, 12 Jan 2026 21:43:35 +1100 Subject: [PATCH] swt: fix build with gcc15 and add darwin support --- pkgs/by-name/sw/swt/package.nix | 55 ++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/pkgs/by-name/sw/swt/package.nix b/pkgs/by-name/sw/swt/package.nix index da7139ae86b1..309ddba5a0e6 100644 --- a/pkgs/by-name/sw/swt/package.nix +++ b/pkgs/by-name/sw/swt/package.nix @@ -31,7 +31,7 @@ stdenv.mkDerivation (finalAttrs: { x86_64-darwin.platform = "cocoa-macosx-x86_64"; x86_64-darwin.hash = "sha256-Uns3fMoetbZAIrL/N0eVd42/3uygXakDdxpaxf5SWDI="; aarch64-darwin.platform = "cocoa-macosx-aarch64"; - aarch64-darwin.hash = "sha256-Uns3fMoetbZAIrL/N0eVd42/3uygXakDdxpaxf5SWDI"; + aarch64-darwin.hash = "sha256-jvxmoRFGquYClPgMqWi2ylw26YiGSG5bONnM1PcjlTM="; }; passthru.srcMetadata = finalAttrs.passthru.srcMetadataByPlatform.${stdenv.hostPlatform.system} or null; @@ -47,25 +47,29 @@ stdenv.mkDerivation (finalAttrs: { url = "https://archive.eclipse.org/eclipse/downloads/drops4/R-${finalAttrs.fullVersion}/swt-${finalAttrs.version}-${srcMetadata.platform}.zip"; inherit (srcMetadata) hash; stripRoot = false; - postFetch = '' - mkdir "$unpackDir" - cd "$unpackDir" + postFetch = + # On Linux, extract and use only the sources from src.zip + lib.optionalString stdenv.hostPlatform.isLinux '' + mkdir "$unpackDir" + cd "$unpackDir" - renamed="$TMPDIR/src.zip" - mv -- "$out/src.zip" "$renamed" - unpackFile "$renamed" - rm -r -- "$out" + renamed="$TMPDIR/src.zip" + mv -- "$out/src.zip" "$renamed" + unpackFile "$renamed" + rm -r -- "$out" - mv -- "$unpackDir" "$out" - ''; + mv -- "$unpackDir" "$out" + ''; }; nativeBuildInputs = [ jdk stripJavaArchivesHook + ] + ++ lib.optionals stdenv.hostPlatform.isLinux [ pkg-config ]; - buildInputs = [ + buildInputs = lib.optionals stdenv.hostPlatform.isLinux [ gtk3 libGLU ]; @@ -76,14 +80,17 @@ stdenv.mkDerivation (finalAttrs: { OUTPUT_DIR = "${placeholder "out"}/lib"; # GTK4 is not supported yet. See: # https://github.com/eclipse-platform/eclipse.platform.swt/issues/652 - makeFlags = "gtk3"; - preBuild = '' + makeFlags = lib.optionals stdenv.hostPlatform.isLinux [ "gtk3" ]; + + NIX_CFLAGS_COMPILE = lib.optionalString stdenv.hostPlatform.isLinux "-std=gnu17"; + postPatch = lib.optionalString stdenv.hostPlatform.isLinux "substituteInPlace library/make_linux.mak --replace-fail 'CFLAGS += -Werror' ''"; + preBuild = lib.optionalString stdenv.hostPlatform.isLinux '' cd library mkdir -p ${finalAttrs.OUTPUT_DIR} ''; - # Build the jar - postBuild = '' + # Build the jar (Linux only, Darwin uses prebuilt) + postBuild = lib.optionalString stdenv.hostPlatform.isLinux '' cd ../ mkdir out find org/ -name '*.java' -type f -exec javac -encoding utf8 -d out/ {} + @@ -97,9 +104,27 @@ stdenv.mkDerivation (finalAttrs: { runHook preInstall install -d -- "$out/jars" + + '' + # On Darwin, use the prebuilt swt.jar which includes native libraries + + lib.optionalString stdenv.hostPlatform.isDarwin '' + # Remove signature files to avoid validation errors after stripJavaArchivesHook modifies the jar + mkdir -p jar-temp + cd jar-temp + ${jdk}/bin/jar -xf ../swt.jar + rm -f META-INF/*.SF META-INF/*.RSA META-INF/*.DSA + ${jdk}/bin/jar -cf "$out/jars/swt.jar" * + cd .. + rm -rf jar-temp + + '' + # On Linux, build from source + + lib.optionalString stdenv.hostPlatform.isLinux '' install -m 644 -t out -- version.txt (cd out && jar -c *) > "$out/jars/swt.jar" + '' + + '' runHook postInstall '';