Skip to content

Commit

Permalink
macOS support for rSharp (#160)
Browse files Browse the repository at this point in the history
Co-authored-by: Robert McIntosh <[email protected]>
Co-authored-by: Félix MIL <[email protected]>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Dec 17, 2024
1 parent 57aa1e8 commit 4efe9a0
Show file tree
Hide file tree
Showing 30 changed files with 449 additions and 369 deletions.
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

0 comments on commit 4efe9a0

Please sign in to comment.