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

openjdk@8 1.8.0-432 #194719

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

calvinit
Copy link
Contributor

@calvinit calvinit commented Oct 17, 2024

  • Have you followed the guidelines for contributing?
  • Have you ensured that your commits follow the commit style guide?
  • Have you checked that there aren't other open pull requests for the same formula update/change?
  • Have you built your formula locally with HOMEBREW_NO_INSTALL_FROM_API=1 brew install --build-from-source <formula>, where <formula> is the name of the formula you're submitting?
  • Is your test running fine brew test <formula>, where <formula> is the name of the formula you're submitting?
  • Does your build pass brew audit --strict <formula> (after doing HOMEBREW_NO_INSTALL_FROM_API=1 brew install --build-from-source <formula>)? If this is a new formula, does it pass brew audit --new <formula>?

@github-actions github-actions bot added legacy Relates to a versioned @ formula no ARM bottle Formula has no ARM bottle labels Oct 17, 2024
@calvinit calvinit mentioned this pull request Oct 17, 2024
6 tasks
@chenrui333 chenrui333 added CI-no-fail-fast Continue CI tests despite failing GitHub Actions matrix builds. CI-no-fail-fast-deps Continue dependent tests despite failing GitHub Actions matrix tests. and removed CI-no-fail-fast Continue CI tests despite failing GitHub Actions matrix builds. labels Oct 17, 2024
@calvinit
Copy link
Contributor Author

calvinit commented Oct 18, 2024

Why is the openjdk version used to test embulk here openjdk@21 instead of openjdk@8? Did the following check fail to work correctly?

on_arm do
  depends_on "openjdk@21"
end
on_intel do
  depends_on "openjdk@8"
end

I printed the content of the embulk script at bin/embulk on my Intel Mac, and it is as follows:

#!/bin/bash
export JAVA_HOME="${JAVA_HOME:-/usr/local/opt/openjdk@8/libexec/openjdk.jdk/Contents/Home}"
exec "${JAVA_HOME}/bin/java"  -jar "/usr/local/Cellar/embulk/0.11.5/libexec/embulk-0.11.5.jar" "$@"

It seems that the JAVA_HOME environment variable already has a value (which is /usr/local/opt/openjdk@21/libexec/openjdk.jdk/Contents/Home), so the subsequent openjdk@8 environment variable value is not being applied. Alternatively, the value of java_version might actually be 21 (java_version = Hardware::CPU.intel? ? "1.8" : "21"). Could this be a bug in the test-bot or brew? Because when testing embulk individually, there is no problem, but here, when it is tested as a dependency of openjdk@8 1.8.0-432, the problem arises.

P.S. def install of embulk.rb:

def install
  java_version = Hardware::CPU.intel? ? "1.8" : "21"
  libexec.install "embulk-#{version}.jar"
  bin.write_jar_script libexec/"embulk-#{version}.jar", "embulk", java_version:
end

@calvinit
Copy link
Contributor Author

Help wanted! @cho-m
Why is the embulk test section unable to correctly retrieve the value of the JAVA_HOME environment variable?
#191470

@chenrui333 chenrui333 added the test failure CI fails while running the test-do block label Oct 21, 2024
@github-actions github-actions bot added the automerge-skip `brew pr-automerge` will skip this pull request label Oct 23, 2024
@github-actions github-actions bot removed the automerge-skip `brew pr-automerge` will skip this pull request label Oct 23, 2024
@github-actions github-actions bot added automerge-skip `brew pr-automerge` will skip this pull request and removed automerge-skip `brew pr-automerge` will skip this pull request labels Oct 24, 2024
@calvinit calvinit force-pushed the openjdk@8_1.8.0-432 branch 6 times, most recently from 79c16e8 to bd657e1 Compare October 25, 2024 11:46
@github-actions github-actions bot added the autosquash Automatically squash pull request commits according to Homebrew style. label Oct 25, 2024
@github-actions github-actions bot removed the autosquash Automatically squash pull request commits according to Homebrew style. label Oct 25, 2024
@calvinit calvinit force-pushed the openjdk@8_1.8.0-432 branch 3 times, most recently from 14edc3f to e34a3cd Compare October 25, 2024 12:41
@chenrui333 chenrui333 added the CI-no-fail-fast Continue CI tests despite failing GitHub Actions matrix builds. label Oct 25, 2024
Formula/o/[email protected] Outdated Show resolved Hide resolved
@github-actions github-actions bot added the autosquash Automatically squash pull request commits according to Homebrew style. label Oct 31, 2024
@github-actions github-actions bot removed the autosquash Automatically squash pull request commits according to Homebrew style. label Oct 31, 2024
@calvinit
Copy link
Contributor Author

calvinit commented Nov 1, 2024

The CI / macOS 14-x86_64 (pull_request) check is working very well now. Please help me review the code, and thank you all for your help. @chenrui333 @carlocab @Bo98

I believe the CI / macOS 15-x86_64 (pull_request) check will also work well. May I ask if it can be added now?

To clarify the changes in this PR, since JNF (JavaNativeFoundation.framework) is incomplete in macOS Sonoma or newer (but openjdk@8 depends on it), we have pre-built it ourselves and are using it.

  • In macOS 13, JNF is linked as a system library:
==> brew linkage --cached openjdk@8
System libraries:
......
  /System/Library/Frameworks/JavaVM.framework/Versions/A/Frameworks/JavaNativeFoundation.framework/Versions/A/JavaNativeFoundation
......
  • In macOS 14 or newer, JNF is installed and linked as a Homebrew library:
==> brew linkage --cached openjdk@8
......
Homebrew libraries:
......
  /usr/local/Cellar/openjdk@8/1.8.0-432/libexec/openjdk.jdk/Contents/Home/Frameworks/JavaNativeFoundation.framework/Versions/A/JavaNativeFoundation (openjdk@8)
......

@calvinit
Copy link
Contributor Author

calvinit commented Nov 1, 2024

Why is the openjdk version used to test embulk here openjdk@21 instead of openjdk@8? Did the following check fail to work correctly?

on_arm do
  depends_on "openjdk@21"
end
on_intel do
  depends_on "openjdk@8"
end

I printed the content of the embulk script at bin/embulk on my Intel Mac, and it is as follows:

#!/bin/bash
export JAVA_HOME="${JAVA_HOME:-/usr/local/opt/openjdk@8/libexec/openjdk.jdk/Contents/Home}"
exec "${JAVA_HOME}/bin/java"  -jar "/usr/local/Cellar/embulk/0.11.5/libexec/embulk-0.11.5.jar" "$@"

It seems that the JAVA_HOME environment variable already has a value (which is /usr/local/opt/openjdk@21/libexec/openjdk.jdk/Contents/Home), so the subsequent openjdk@8 environment variable value is not being applied. Alternatively, the value of java_version might actually be 21 (java_version = Hardware::CPU.intel? ? "1.8" : "21"). Could this be a bug in the test-bot or brew? Because when testing embulk individually, there is no problem, but here, when it is tested as a dependency of openjdk@8 1.8.0-432, the problem arises.

P.S. def install of embulk.rb:

def install
  java_version = Hardware::CPU.intel? ? "1.8" : "21"
  libexec.install "embulk-#{version}.jar"
  bin.write_jar_script libexec/"embulk-#{version}.jar", "embulk", java_version:
end

I opened an issue: Homebrew/brew#18695

@Bo98
Copy link
Member

Bo98 commented Nov 1, 2024

To clarify the changes in this PR, since JNF (JavaNativeFoundation.framework) is incomplete in macOS Sonoma or newer (but openjdk@8 depends on it), we have pre-built it ourselves and are using it.

Did you try the header thing I suggested? I ask because in theory it should still be possible to link against system JNF as the linker information does still ship with the SDK - only the headers were removed:

resource("JavaNativeFoundation").stage(buildpath/"JNF")
args << "--with-extra-cflags=-isystem #{buildpath/"JNF/apple/JavaNativeFoundation"}"

@calvinit
Copy link
Contributor Author

calvinit commented Nov 1, 2024

To clarify the changes in this PR, since JNF (JavaNativeFoundation.framework) is incomplete in macOS Sonoma or newer (but openjdk@8 depends on it), we have pre-built it ourselves and are using it.

Did you try the header thing I suggested? I ask because in theory it should still be possible to link against system JNF as the linker information does still ship with the SDK - only the headers were removed:

resource("JavaNativeFoundation").stage(buildpath/"JNF")
args << "--with-extra-cflags=-isystem #{buildpath/"JNF/apple/JavaNativeFoundation"}"

Not yet, as I don’t know where to download these headers. However, there’s an error that might indicate it won’t necessarily work: '/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/System/Library/Frameworks/JavaNativeFoundation.framework/Versions/A/JavaNativeFoundation' (no such file)

@Bo98
Copy link
Member

Bo98 commented Nov 1, 2024

That was using the resource you already have.

The test I ran locally was:

$ clang -arch x86_64 -isystem $(/usr/libexec/java_home)/include -isystem $(/usr/libexec/java_home)/include/darwin -isystem openjdk-iTunesOpenJDK-1014.0.2.12.1/apple/JavaNativeFoundation/ -framework JavaNativeFoundation test.m

(java_home stuff not needed in an OpenJDK build - just was because I was running it from outside)

#include <JavaNativeFoundation/JavaNativeFoundation.h>

int main()
{
    printf("%f\n", JNFJavaMillisToNSTimeInterval(978307210000)); // should equal 10.0
    return 0;
}
$ ./a.out
10.000000
$ otool -L a.out
a.out:
	/System/Library/Frameworks/JavaNativeFoundation.framework/Versions/A/JavaNativeFoundation (compatibility version 1.0.0, current version 84.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1345.100.2)

@calvinit calvinit force-pushed the openjdk@8_1.8.0-432 branch 3 times, most recently from 3dae490 to 77955fd Compare November 1, 2024 11:06
@calvinit
Copy link
Contributor Author

calvinit commented Nov 1, 2024

That was using the resource you already have.

The test I ran locally was:

$ clang -arch x86_64 -isystem $(/usr/libexec/java_home)/include -isystem $(/usr/libexec/java_home)/include/darwin -isystem openjdk-iTunesOpenJDK-1014.0.2.12.1/apple/JavaNativeFoundation/ -framework JavaNativeFoundation test.m

(java_home stuff not needed in an OpenJDK build - just was because I was running it from outside)

#include <JavaNativeFoundation/JavaNativeFoundation.h>

int main()
{
    printf("%f\n", JNFJavaMillisToNSTimeInterval(978307210000)); // should equal 10.0
    return 0;
}
$ ./a.out
10.000000
$ otool -L a.out
a.out:
	/System/Library/Frameworks/JavaNativeFoundation.framework/Versions/A/JavaNativeFoundation (compatibility version 1.0.0, current version 84.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1345.100.2)

@Bo98 Hi, I have tried, but it still doesn't work, whether it's -I or -isystem.

==> bash configure --with-boot-jdk-jvmargs=-Duser.home=/Users/brew/Library/Caches/Homebrew/java_cache --with-boot-jdk=/private/tmp/openjdkA8-20241101-6360-t2tyje/jdk8u-jdk8u432-ga/boot-jdk --with-debug-level=release --with-conf-name=release --with-jvm-variants=server --with-milestone=fcs --with-native-debug-symbols=none --with-update-version=432 --with-vendor-bug-url=https://github.com/Homebrew/homebrew-core/issues --with-vendor-name=Homebrew --with-vendor-url=https://github.com/Homebrew/homebrew-core/issues --with-vendor-vm-bug-url=https://github.com/Homebrew/homebrew-core/issues --with-giflib=system --with-toolchain-type=clang --with-zlib=system --with-extra-cflags=-isystem/private/tmp/JavaNativeFoundation-20241101-6360-wbss6w/openjdk-iTunesOpenJDK-1014.0.2.12.1/apple/JavaNativeFoundation/JavaNativeFoundation --with-extra-cxxflags=-isystem/private/tmp/JavaNativeFoundation-20241101-6360-wbss6w/openjdk-iTunesOpenJDK-1014.0.2.12.1/apple/JavaNativeFoundation/JavaNativeFoundation --with-extra-ldflags=-Wl,-rpath,@loader_path/server -Wl,-rpath,/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/System/Library/Frameworks

See: https://github.com/Homebrew/homebrew-core/actions/runs/11634188568/job/32401061493?pr=194719#step:3:1131

Compiling /private/tmp/openjdkA8-20241101-6360-t2tyje/jdk8u-jdk8u432-ga/hotspot/src/share/vm/runtime/vm_version.cpp
  /private/tmp/openjdkA8-20241101-6360-t2tyje/jdk8u-jdk8u432-ga/hotspot/agent/src/os/bsd/MacosxDebuggerLocal.m:27:9: fatal error: 'JavaNativeFoundation/JavaNativeFoundation.h' file not found
     27 | #import <JavaNativeFoundation/JavaNativeFoundation.h>
        |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  /private/tmp/openjdkA8-20241101-6360-t2tyje/jdk8u-jdk8u432-ga/hotspot/agent/src/os/bsd/MacosxDebuggerLocal.m:27:9: note: did not find header 'JavaNativeFoundation.h' in framework 'JavaNativeFoundation' (loaded from '/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/System/Library/Frameworks')
  1 error generated.
  make[6]: *** [libsaproc.dylib] Error 1
  make[6]: *** Waiting for unfinished jobs....

From the error log above, it seems that it will look for headers in framework 'JavaNativeFoundation' rather than those provided by -I or -isystem (note: did not find header 'JavaNativeFoundation.h' in framework 'JavaNativeFoundation').

What did I mainly change? ↓↓↓

if OS.mac?
  # Work around Xcode 16 bug: https://bugs.openjdk.org/browse/JDK-8340341
  ENV.append_to_cflags("-mllvm -enable-constraint-elimination=0") if DevelopmentTools.clang_build_version == 1600

  args += %w[
    --with-toolchain-type=clang
    --with-zlib=system
  ]

  # NOTE: Since macOS Sonoma or newer do not include the required headersfor JNF (JavaNativeFoundation.framework),
  # so we will use the headers provided at https://github.com/apple/openjdk.
  if MacOS.version >= :sonoma
    resource "JavaNativeFoundation" do
      url "https://github.com/apple/openjdk/archive/refs/tags/iTunesOpenJDK-1014.0.2.12.1.tar.gz"
      sha256 "e8556a73ea36c75953078dfc1bafc9960e64593bc01e733bc772d2e6b519fd4a"

      stage do
        jnf_headers_search_path = Pathname.pwd/"apple/JavaNativeFoundation/JavaNativeFoundation"
        args += %W[
          --with-extra-cflags=-isystem#{jnf_headers_search_path}
          --with-extra-cxxflags=-isystem#{jnf_headers_search_path}
        ]
      end
    end

    ldflags << "-Wl,-rpath,#{MacOS.sdk_path}/System/Library/Frameworks"
  end
#......
end

@calvinit calvinit force-pushed the openjdk@8_1.8.0-432 branch 2 times, most recently from 133c53c to 34e252c Compare November 1, 2024 17:18
@github-actions github-actions bot added the automerge-skip `brew pr-automerge` will skip this pull request label Nov 1, 2024
@github-actions github-actions bot removed the automerge-skip `brew pr-automerge` will skip this pull request label Nov 1, 2024
@calvinit calvinit force-pushed the openjdk@8_1.8.0-432 branch 4 times, most recently from 172dd0a to b069910 Compare November 1, 2024 19:08
@Bo98
Copy link
Member

Bo98 commented Nov 1, 2024

Looks like there's one part that doesn't accept --with-extra-cflags properly, but something like this instead does work: Bo98@940717f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI-no-fail-fast Continue CI tests despite failing GitHub Actions matrix builds. CI-no-fail-fast-deps Continue dependent tests despite failing GitHub Actions matrix tests. legacy Relates to a versioned @ formula no ARM bottle Formula has no ARM bottle test failure CI fails while running the test-do block
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants