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

macOS support for rSharp #160

Merged
merged 27 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5ba9cf0
wip - this version does not co-exist with a linux build. The makefile…
rwmcintosh Dec 12, 2024
780cc87
Allow dotnet 9
Dec 13, 2024
243e403
explicitely check for dotnet8
Dec 13, 2024
5bf99e9
try-catch changes
rwmcintosh Dec 13, 2024
b2fdf38
support dual nix builds for mac and linux
rwmcintosh Dec 13, 2024
2a5bc53
add macos build in gha
Dec 13, 2024
2076e24
Load macos native library
Dec 13, 2024
d58c79c
Merge branch 'mac_build' of https://github.com/Open-Systems-Pharmacol…
Dec 13, 2024
b0c4c63
fix path rSharp.mac.so
Dec 13, 2024
83d4544
loads rSharp.linux.so on linux
Dec 13, 2024
ffe3383
separate base pkgName and nativePkgName in two variables
Dec 13, 2024
a7f840d
update rSharp lib names for linux and macos
rwmcintosh Dec 13, 2024
18ce8c2
Add entry in NEWS
Dec 13, 2024
d95489c
back to setup-dotnet@v1
Felixmil Dec 13, 2024
9a7c131
use ubuntu 22 runner (for nuget)
Felixmil Dec 13, 2024
d1105bc
Update Linux C# binaries (Commit from Github Actions).
github-actions[bot] Dec 13, 2024
df840fc
install R before running make
Felixmil Dec 13, 2024
44f5bd2
Merge branch 'mac_build' of https://github.com/Open-Systems-Pharmacol…
Felixmil Dec 13, 2024
eafa7e5
run builds one after another
Felixmil Dec 13, 2024
448248a
make workflow steps cancellable
Felixmil Dec 13, 2024
26c3817
working tests
rwmcintosh Dec 16, 2024
4aeec95
Update macOS C# binaries (Commit from Github Actions).
github-actions[bot] Dec 16, 2024
a2e8197
Update Windows C# binaries (Commit from Github Actions).
github-actions[bot] Dec 16, 2024
d386be6
fix test for macos
Felixmil Dec 16, 2024
2a08ef2
Improve GitHub Actions
Felixmil Dec 16, 2024
f53bcb4
Update Linux C# binaries (Commit from Github Actions).
github-actions[bot] Dec 16, 2024
55dcdeb
Update Windows C# binaries (Commit from Github Actions).
github-actions[bot] Dec 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,32 @@ jobs:
fail-fast: false
matrix:
config:
# - {os: macos-latest, r: 'release'}
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
# - {os: ubuntu-latest, r: 'oldrel-1'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}

- uses: r-lib/actions/setup-pandoc@v2

- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 8.0.x

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- name: install ubuntu dependencies
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install dotnet-runtime-8.0 libcurl4-openssl-dev libssl-dev libxml2-dev
sudo apt-get install libfontconfig1-dev libharfbuzz-dev libfribidi-dev
sudo apt-get install libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev
sudo ln -s /usr/lib/x86_64-linux-gnu/libdl.so.2 /usr/lib/x86_64-linux-gnu/libdl.so

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
Expand All @@ -67,7 +63,7 @@ jobs:

- name: Get package version from DESCRIPTION file and set as environment variable
run: |
echo "PKG_VERSION=$(grep -oP '(?<=Version: )\d+\.\d+\.\d+\.*\d*' DESCRIPTION)" >> $GITHUB_ENV
echo "PKG_VERSION=$(grep '^Version: ' DESCRIPTION | sed -E 's/^Version: ([0-9]+\.[0-9]+\.[0-9]+\.?[0-9]*)/\1/')" >> $GITHUB_ENV
echo "$PKG_VERSION"
shell: bash

Expand Down
65 changes: 49 additions & 16 deletions .github/workflows/build-c#.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,101 @@ on:

jobs:
Linux-Build:

runs-on: ubuntu-latest
runs-on: ubuntu-22.04
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4
if: ${{ github.event_name == 'pull_request' }}
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}

- uses: actions/checkout@v4
if: ${{ github.event_name != 'pull_request' }}

- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 8.0.x

- name: Setup R
uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- name: Make
working-directory: ./shared
run: make

- name: Test C# binaries
run: |
export R_HOME=/usr/lib/R
dotnet test ./shared/RDotNet.Tests/ -c Release -d log.txt --no-build
dotnet test ./shared/rSharpTests/ -c Release -d log.txt --no-build
dotnet test ./shared/DynamicInterop.Tests/ -c Release -d log.txt --no-build

- uses: EndBug/add-and-commit@v9
if: ${{ success() }}
with:
pull: '--verbose'
message: 'Update Linux C# binaries (Commit from Github Actions).'
default_author: github_actions
add: '*linux.so'


macOS-Build:
runs-on: macos-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}

- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 8.0.x

- name: Setup R
uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- name: Make
working-directory: ./shared
run: make

- name: Test C# binaries
run: |
export R_HOME=/usr/lib/R
export R_HOME=/Library/Frameworks/R.framework/Resources
dotnet test ./shared/RDotNet.Tests/ -c Release -d log.txt --no-build
dotnet test ./shared/rSharpTests/ -c Release -d log.txt --no-build
dotnet test ./shared/DynamicInterop.Tests/ -c Release -d log.txt --no-build

- uses: EndBug/add-and-commit@v9
if: ${{ success() }}
with:
message: 'Update Linux C# binaries (Commit from Github Actions).'
pull: '--verbose'
message: 'Update macOS C# binaries (Commit from Github Actions).'
default_author: github_actions
add: '*.so'
add: '*mac.so'


Windows-Build:
needs: Linux-Build
runs-on: windows-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4
if: ${{ github.event_name == 'pull_request' }}
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}

- uses: actions/checkout@v4
if: ${{ github.event_name != 'pull_request' }}

- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
Expand All @@ -77,7 +111,6 @@ jobs:
with:
use-public-rspm: true


- name: Install dependencies
run: |
nuget restore ./shared/packages.config -PackagesDirectory ./shared/packages
Expand All @@ -97,10 +130,10 @@ jobs:
dotnet test .\shared\rSharpTests\ -c Release -d log.txt --no-build
dotnet test .\shared\DynamicInterop.Tests\ -c Release -d log.txt --no-build


- uses: EndBug/add-and-commit@v9
if: ${{ success() }}
with:
pull: '--verbose'
message: 'Update Windows C# binaries (Commit from Github Actions).'
default_author: github_actions
add: '*.dll'
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
name: PR-Workflow

on:
push:
branches: [main]
pull_request:
workflow_dispatch:


jobs:


# Detect changes done in C# code base. If no change were done, skim "build-Csharp-binaries" workflow.
changes:
detect-changes:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
permissions:
pull-requests: read
Expand All @@ -17,23 +21,37 @@ jobs:
- uses: dorny/paths-filter@v3
id: filter
with:
base: ${{ github.ref }}
filters: |
Csharp:
- 'shared/**'

build-Csharp-binaries:
needs: changes
if: ${{ needs.changes.outputs.Csharp == 'true' }}
needs: detect-changes
if: ${{ needs.detect-changes.outputs.Csharp == 'true' && github.event_name == 'pull_request'}}
uses: ./.github/workflows/build-c#.yaml
R-CMD-Check:
if: ${{ always() }}

# Automatically bump dev version when a it is a push to main branch
bump-dev-version:
needs: build-Csharp-binaries
if: github.event_name != 'pull_request' # only when merging in main/develop branch
uses: Open-Systems-Pharmacology/Workflows/.github/workflows/bump_dev_version_tag_branch.yaml@main
with:
app-id: ${{ vars.VERSION_BUMPER_APPID }}
secrets:
private-key: ${{ secrets.VERSION_BUMPER_SECRET }}

R-CMD-Check:
if: ${{ !cancelled() }}
needs: bump-dev-version
uses: ./.github/workflows/R-CMD-check.yaml

test-coverage:
if: ${{ always() }}
if: ${{ !cancelled() }}
needs: [R-CMD-Check]
uses: ./.github/workflows/test-coverage.yaml

pkgdown:
if: ${{ always() }}
if: ${{ !cancelled() }}
needs: [R-CMD-Check]
uses: ./.github/workflows/pkgdown.yaml
18 changes: 0 additions & 18 deletions .github/workflows/merge-workflow.yaml

This file was deleted.

5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# rSharp (development version)

## Major changes

- rSharp is now compatible with macOS (tested on ARM)


# rSharp 1.0.1

## Minor improvements and bug fixes
Expand Down
106 changes: 57 additions & 49 deletions R/rSharp-env.R
Original file line number Diff line number Diff line change
@@ -1,49 +1,57 @@
# Environment that holds various global variables and settings for the package.
# It is not exported and should not be directly manipulated by other packages.
rSharpEnv <- new.env(parent = emptyenv())

# name of the package. This will be used to retrieve information on the package at run time
rSharpEnv$packageName <- "rSharp"
# Name of the C++ redistributable library
rSharpEnv$msvcrFileName <- "msvcp140.dll"
# The name of the native (C++) library
rSharpEnv$nativePkgName <- "rSharp"
# Name of the .NET library
rSharpEnv$dotnetPkgName <- "ClrFacade"

# Full type name of the main facade to the interop code written in C#
rSharpEnv$clrFacadeTypeName <- "ClrFacade.ClrFacade"
# Full type name of the test cases
rSharpEnv$testCasesTypeName <- "ClrFacade.TestCases"
# Full name of test object class
rSharpEnv$testObjectTypeName <- "ClrFacade.TestObject"
rSharpEnv$testMethodBindingTypeName <- "ClrFacade.TestMethodBinding"


#' Names of the settings stored in rSharpEnv Can be used with `getRSharpSetting()`
#' @export
rSharpSettingNames <- names(rSharpEnv)

#' @title getRSharpSetting
#' @description Get the value of a global rSharp setting.
#'
#' @param settingName String name of the setting
#'
#' @return Value of the setting stored in rSharpEnv. If the setting does not exist, an error is thrown.
#' @export
#'
#' @examples
#' getRSharpSetting("nativePkgName")
getRSharpSetting <- function(settingName) {
if (!(any(names(rSharpEnv) == settingName))) {
stop(messages$errorPackageSettingNotFound(settingName, rSharpEnv))
}

obj <- rSharpEnv[[settingName]]
# Evaluate if the object is a function. This is required since some properties are defined as function reference
if (is.function(obj)) {
return(obj())
}

return(obj)
}
# Environment that holds various global variables and settings for the package.
# It is not exported and should not be directly manipulated by other packages.
rSharpEnv <- new.env(parent = emptyenv())

# name of the package. This will be used to retrieve information on the package at run time
rSharpEnv$packageName <- "rSharp"
# Name of the C++ redistributable library
rSharpEnv$msvcrFileName <- "msvcp140.dll"
# The name of the package
rSharpEnv$pkgName <- "rSharp"

# The name of the native (C++) library
rSharpEnv$nativePkgName <-
switch(Sys.info()[['sysname']],
Windows = rSharpEnv$pkgName,
Linux = {paste0(rSharpEnv$pkgName, ".linux")},
Darwin = {paste0(rSharpEnv$pkgName,".mac")})

# Name of the .NET library
rSharpEnv$dotnetPkgName <- "ClrFacade"

# Full type name of the main facade to the interop code written in C#
rSharpEnv$clrFacadeTypeName <- "ClrFacade.ClrFacade"
# Full type name of the test cases
rSharpEnv$testCasesTypeName <- "ClrFacade.TestCases"
# Full name of test object class
rSharpEnv$testObjectTypeName <- "ClrFacade.TestObject"
rSharpEnv$testMethodBindingTypeName <- "ClrFacade.TestMethodBinding"


#' Names of the settings stored in rSharpEnv Can be used with `getRSharpSetting()`
#' @export
rSharpSettingNames <- names(rSharpEnv)

#' @title getRSharpSetting
#' @description Get the value of a global rSharp setting.
#'
#' @param settingName String name of the setting
#'
#' @return Value of the setting stored in rSharpEnv. If the setting does not exist, an error is thrown.
#' @export
#'
#' @examples
#' getRSharpSetting("nativePkgName")
getRSharpSetting <- function(settingName) {
if (!(any(names(rSharpEnv) == settingName))) {
stop(messages$errorPackageSettingNotFound(settingName, rSharpEnv))
}

obj <- rSharpEnv[[settingName]]
# Evaluate if the object is a function. This is required since some properties are defined as function reference
if (is.function(obj)) {
return(obj())
}

return(obj)
}
Loading