Unverified Commit b82e1c9c authored by Doron Behar's avatar Doron Behar Committed by GitHub
Browse files

swt: fix build with gcc15 and add darwin support (#479303)

parents 538f7045 c26fd684
Loading
Loading
Loading
Loading
+40 −15
Original line number Diff line number Diff line
@@ -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,7 +47,9 @@ 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 = ''
      postFetch =
        # On Linux, extract and use only the sources from src.zip
        lib.optionalString stdenv.hostPlatform.isLinux ''
          mkdir "$unpackDir"
          cd "$unpackDir"

@@ -63,9 +65,11 @@ stdenv.mkDerivation (finalAttrs: {
  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
  '';