-
-
Notifications
You must be signed in to change notification settings - Fork 219
Update OpenMP plugin to detect and handle Apple clang on macOS #1409
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3c2907d
Modified the openmp plugin to properly detect macOS and differentiate…
coatless 8bc698c
Add ChangeLog entry
coatless 6789a7f
Update OpenMP plugin scaffolding for macOS based on feedback
coatless c3fd7d4
Whitespace tweak after rebase to parentrepo main branch
eddelbuettel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,10 @@ | |
| or related R headers were installed first | ||
| * inst/include/RcppCommon.h: Call new header as first thing | ||
|
|
||
| 2025-11-18 James J Balamuta <[email protected]> | ||
|
|
||
| * R/Attributes.R: Updated OpenMP Plugin's flags on macOS | ||
|
|
||
| 2025-11-04 Dirk Eddelbuettel <[email protected]> | ||
|
|
||
| * .github/workflows/macos.yaml (jobs): Roll macos-13 to macos-14 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -588,8 +588,52 @@ compileAttributes <- function(pkgdir = ".", verbose = getOption("verbose")) { | |||||
|
|
||||||
| ## built-in OpenMP plugin | ||||||
| .plugins[["openmp"]] <- function() { | ||||||
| list(env = list(PKG_CXXFLAGS="-fopenmp", | ||||||
| PKG_LIBS="-fopenmp")) | ||||||
|
|
||||||
| # Default flags for non-macOS systems | ||||||
| cxxflags <- "-fopenmp" | ||||||
| libs <- "-fopenmp" | ||||||
|
|
||||||
| # Check if we're on macOS | ||||||
| if (Sys.info()[["sysname"]] == "Darwin") { | ||||||
| # Get the C++ compiler from R CMD config CXX | ||||||
| r_cmd <- file.path(R.home("bin"), "R") | ||||||
| cxx <- tryCatch({ | ||||||
| system2(r_cmd, c("CMD", "config", "CXX"), stdout = TRUE, stderr = FALSE) | ||||||
| }, error = function(e) "") | ||||||
|
|
||||||
| if (length(cxx) > 0 && nzchar(cxx[1])) { | ||||||
| # Check compiler version using full command (this includes any flags) | ||||||
| compiler_version <- tryCatch({ | ||||||
| system(paste(cxx[1], "--version"), intern = TRUE, ignore.stderr = TRUE) | ||||||
| }, error = function(e) character(0)) | ||||||
|
|
||||||
| if (length(compiler_version) > 0) { | ||||||
| # Check for Apple clang | ||||||
| is_apple_clang <- any(grepl("Apple", compiler_version, ignore.case = TRUE)) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| # Check for Homebrew clang | ||||||
| is_homebrew_clang <- any(grepl("Homebrew", compiler_version, ignore.case = TRUE)) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| if (is_apple_clang) { | ||||||
| # Apple clang requires -Xclang -fopenmp | ||||||
| cxxflags <- "-Xclang -fopenmp" | ||||||
| libs <- "-lomp" | ||||||
| } else if (is_homebrew_clang) { | ||||||
| # Homebrew clang needs include/lib paths for the added libomp formula | ||||||
| # Determine prefix based on architecture (arm64 vs x86_64) | ||||||
| arch <- Sys.info()[["machine"]] | ||||||
| brew_prefix <- if (arch == "arm64") "/opt/homebrew" else "/usr/local" | ||||||
|
|
||||||
| cxxflags <- paste("-Xclang -fopenmp", | ||||||
| paste0("-I", brew_prefix, "/opt/libomp/include")) | ||||||
| libs <- paste(paste0("-L", brew_prefix, "/opt/libomp/lib"), "-lomp") | ||||||
| } | ||||||
| # Otherwise it's gcc and regular -fopenmp works (defaults are fine) | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| list(env = list(PKG_CXXFLAGS = cxxflags, | ||||||
| PKG_LIBS = libs)) | ||||||
| } | ||||||
|
|
||||||
| .plugins[["unwindProtect"]] <- function() { # nocov start | ||||||
|
|
||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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 check also succeeds (and is checked in the conditional) for Homebrew's build of clang, since it has
and so
appleis picked up in the grep invocation from the target triple.