Skip to content

Commit f09ed1b

Browse files
authored
Merge pull request #28 from wwlwpd/master
fixing bug (#27) and updating tests
2 parents 0aa9ecf + 083f033 commit f09ed1b

File tree

6 files changed

+138
-55
lines changed

6 files changed

+138
-55
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,50 +7,6 @@ on:
77
- '*'
88
pull_request:
99
jobs:
10-
ubuntu:
11-
runs-on: ${{ matrix.os }}
12-
strategy:
13-
fail-fast: false
14-
matrix:
15-
os: [ubuntu-latest]
16-
perl-version: ['5.10', '5.14', '5.20', '5.28', '5.32']
17-
include:
18-
- perl-version: '5.30'
19-
os: ubuntu-latest
20-
release-test: true
21-
coverage: true
22-
container: perl:${{ matrix.perl-version }}
23-
steps:
24-
- uses: actions/checkout@v2
25-
- uses: perl-actions/install-with-cpanm@v1
26-
with:
27-
args: -n --installdeps --with-recommends .
28-
sudo: false
29-
- run: perl -V
30-
- name: Build
31-
run: |
32-
perl Makefile.PL
33-
make
34-
- name: Run release tests # before others as may install useful stuff
35-
if: ${{ matrix.release-test }}
36-
env:
37-
RELEASE_TESTING: 1
38-
run: |
39-
apt-get update && apt-get install -y libfile-copy-recursive-perl
40-
cpanm -n --installdeps --with-develop .
41-
prove -brj4 xt
42-
- name: Run tests (no coverage)
43-
if: ${{ !matrix.coverage }}
44-
run: prove -brj4 t
45-
- name: Run tests (with coverage)
46-
if: ${{ matrix.coverage }}
47-
env:
48-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49-
RELEASE_TESTING: 1
50-
run: |
51-
cpanm -n Devel::Cover::Report::Coveralls
52-
HARNESS_PERL_SWITCHES='-MDevel::Cover=-delete,-ignore,Alien/OpenMP/Install/Files\\.pm$' prove -brj4 t xt
53-
cover -report Coveralls
5410
non-linux:
5511
runs-on: ${{ matrix.os }}
5612
strategy:
@@ -69,7 +25,7 @@ jobs:
6925
- name: Run tests
7026
run: |
7127
perl Makefile.PL
72-
make
28+
gmake
7329
prove -brj4 t
7430
darwin:
7531
runs-on: macOS-latest

.github/workflows/test-gccs.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Perl CI with Inline::C and OpenMP
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ${{ matrix.os }}
8+
strategy:
9+
fail-fast: false # Ensure all jobs run even if one fails
10+
matrix:
11+
os: ["ubuntu-latest"]
12+
perl: ["5.40.1", "5.38.3", "5.36.3", "5.34.3", "5.32.1", "5.30.3", "5.28.3", "5.26.3", "5.24.4", "5.22.3", "5.20.0", "5.18.4", "5.16.3", "5.14.4", "5.12.5"]
13+
gcc: ["13", "11", "9"] # Different GCC versions to test
14+
15+
name: Perl ${{ matrix.perl }} with GCC-${{ matrix.gcc }} on ${{ matrix.os }}
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
# Install the requested GCC version and dependencies
21+
- name: Install GCC-${{ matrix.gcc }} and Dependencies
22+
run: |
23+
sudo apt update
24+
sudo apt install -y gcc-${{ matrix.gcc }} g++-${{ matrix.gcc }} build-essential libgomp1 curl
25+
26+
# Switch GCC at the OS level using update-alternatives
27+
- name: Set GCC-${{ matrix.gcc }} as Default
28+
run: |
29+
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${{ matrix.gcc }} 100
30+
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-${{ matrix.gcc }} 100
31+
sudo update-alternatives --set gcc /usr/bin/gcc-${{ matrix.gcc }}
32+
sudo update-alternatives --set g++ /usr/bin/g++-${{ matrix.gcc }}
33+
34+
export CC=/usr/bin/gcc
35+
export CXX=/usr/bin/g++
36+
echo "CC=$CC" >> $GITHUB_ENV
37+
echo "CXX=$CXX" >> $GITHUB_ENV
38+
39+
echo "Using system GCC version:"
40+
gcc --version
41+
42+
# Install Perlbrew
43+
- name: Install Perlbrew
44+
run: |
45+
curl -L https://install.perlbrew.pl | bash
46+
echo 'export PERLBREW_ROOT=$HOME/perl5/perlbrew' >> $HOME/.bashrc
47+
echo 'source $HOME/perl5/perlbrew/etc/bashrc' >> $HOME/.bashrc
48+
export PERLBREW_ROOT=$HOME/perl5/perlbrew
49+
export PATH="$PERLBREW_ROOT/bin:$PATH"
50+
source $HOME/perl5/perlbrew/etc/bashrc
51+
perlbrew available
52+
53+
# Install and Use the Requested Perl Version
54+
- name: Install Perl ${{ matrix.perl }} with GCC-${{ matrix.gcc }}
55+
run: |
56+
export PERLBREW_ROOT=$HOME/perl5/perlbrew
57+
export PATH="$PERLBREW_ROOT/bin:$PATH"
58+
source $HOME/perl5/perlbrew/etc/bashrc
59+
60+
perlbrew --verbose --notest install perl-${{ matrix.perl }} -Dcc=$CC
61+
perlbrew use perl-${{ matrix.perl }}
62+
perlbrew install-cpanm
63+
64+
perl -V
65+
perl -v
66+
67+
# Install Required Perl Modules
68+
- name: Install Required Perl Modules
69+
run: |
70+
export PERLBREW_ROOT=$HOME/perl5/perlbrew
71+
export PATH="$PERLBREW_ROOT/bin:$PATH"
72+
source $HOME/perl5/perlbrew/etc/bashrc
73+
perlbrew use perl-${{ matrix.perl }}
74+
cpanm --verbose --notest Inline::C
75+
cpanm --verbose .

Changes

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
{{$NEXT}}
2-
- doc tweaks
1+
0.003007 2022-05-14 20:04:34+01:00 Europe/London
2+
- Fixing build that breaks when CNAME is a path to
3+
gcc and not just "gcc"
34

45
0.003006 2021-11-01 21:46:06+01:00 Europe/London
56
- Updated Inline::C integration via Alien::OpenMP::Inline

dist.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ name = Alien-OpenMP
22
license = Perl_5
33
author = oodler <[email protected]>
44
copyright_holder = oodler
5-
copyright_year = 2021
5+
copyright_year = 2021-present
6+
[VersionFromModule]
67
[@Starter::Git]
78
revision = 5
8-
managed_versions = 1
99
regenerate = Makefile.PL
1010
regenerate = META.json
1111
[AlienBuild]

lib/Alien/OpenMP/configure.pm

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use strict;
33
use warnings;
44
use Config;
55

6-
our $CCNAME = $ENV{CC} || $Config::Config{ccname};
6+
# ExtUtils::CBuilder uses cc not ccname
7+
our $CCNAME = $ENV{CC} || $Config::Config{cc};
78
our $OS = $^O;
89

910
my $checked = 0;
@@ -84,8 +85,20 @@ sub version_from_preprocessor {
8485

8586
sub _openmp_defined {
8687
my $define = pop;
88+
8789
# From https://github.com/jeffhammond/HPCInfo/blob/master/docs/Preprocessor-Macros.md
88-
my $versions = {200505 => '2.5', 200805 => '3.0', 201107 => '3.1', 201307 => '4.0', 201511 => '4.5', 201811 => '5.0'};
90+
# also https://www.openmp.org/specifications/
91+
my $versions = {
92+
200505 => '2.5',
93+
200805 => '3.0',
94+
201107 => '3.1',
95+
201307 => '4.0',
96+
201511 => '4.5',
97+
201811 => '5.0',
98+
202011 => '5.1',
99+
202111 => '5.2',
100+
202411 => '6.0',
101+
};
89102
return $versions->{$define || ''} || 'unknown';
90103
}
91104

@@ -94,12 +107,30 @@ sub _reset { $checked = 0; }
94107

95108
sub _update_supported {
96109
return if $checked;
110+
require File::Basename;
111+
112+
# handles situation where $CCNAME is gcc as part of a path
113+
$CCNAME = File::Basename::basename($CCNAME);
114+
97115
if ($OS eq 'darwin') {
98116
require File::Which;
99117
require Path::Tiny;
100118

101119
# The issue here is that ccname=gcc and cc=cc as an interface to clang
102-
$supported->{darwin} = {cflags => ['-Xclang', '-fopenmp'], libs => ['-lomp'],};
120+
# First check if clang/gcc, then discern omp location
121+
my $flavour = _compiler_flavour();
122+
if ($flavour eq 'clang' || $flavour eq 'default') {
123+
$supported->{darwin} = {cflags => ['-Xclang', '-fopenmp'], libs => ['-lomp'],};
124+
$supported->{$CCNAME} ||= {auto_include => join qq{\n}, ('#include <omp.h>')};
125+
}
126+
elsif ($flavour eq 'gcc') {
127+
$supported->{darwin} = {cflags => ['-fopenmp'], libs => ['-lomp'],};
128+
$supported->{$CCNAME} ||= {auto_include => join qq{\n}, ('#include <omp.h>')};
129+
}
130+
else {
131+
return ++$checked;
132+
}
133+
103134
if (my $mp = File::Which::which('port')) {
104135

105136
# macports /opt/local/bin/port
@@ -108,14 +139,22 @@ sub _update_supported {
108139
unshift @{$supported->{darwin}{libs}}, "-L$mp_prefix/lib/libomp";
109140
}
110141
else {
111-
# homebrew has the headers and library in /usr/local
112-
push @{$supported->{darwin}{cflags}}, "-I/usr/local/include";
113-
unshift @{$supported->{darwin}{libs}}, "-L/usr/local/lib";
142+
# homebrew has the headers and library in /usr/local, but is not always symlinked
143+
push @{$supported->{darwin}{cflags}}, "-I/usr/local/include", "-I/opt/homebrew/opt/libomp/include";
144+
unshift @{$supported->{darwin}{libs}}, "-L/usr/local/lib", "-L/opt/homebrew/opt/libomp/lib";
114145
}
115146
}
116147
$checked++;
117148
}
118149

150+
# not looking for openmp
151+
sub _compiler_flavour {
152+
my $defines = qx{$CCNAME -dM -E - < /dev/null};
153+
return 'clang' if ($defines =~ m{^#define __clang__}m);
154+
return 'gcc' if ($defines =~ m{^#define __GCC_}m && $defines =~ m{^#define __APPLE__}m);
155+
return 'default';
156+
}
157+
119158
1;
120159

121160
=encoding utf8

t/03-configure.t

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ subtest 'gcc' => sub {
2525
};
2626

2727
subtest 'darwin clang/gcc homebrew' => sub {
28+
plan skip_all => 'Mocking does not work on MSWin32'
29+
if $^O eq 'MSWin32';
2830
local $Alien::OpenMP::configure::CCNAME = 'gcc';
2931
local $Alien::OpenMP::configure::OS = 'darwin';
3032
local $ENV{PATH} = "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin";
@@ -86,6 +88,16 @@ subtest 'darwin, missing dependencies' => sub {
8688
like $stderr, qr{Support can be enabled by using Homebrew or Macports}, 'unsupported compiler name';
8789
};
8890

91+
subtest '/full/path/to/gcc' => sub {
92+
local $Alien::OpenMP::configure::CCNAME = '/full/path/to/gcc';
93+
local $Alien::OpenMP::configure::OS = 'linux';
94+
my $omp_flag = q{-fopenmp};
95+
Alien::OpenMP::configure->_reset;
96+
is +Alien::OpenMP::configure->is_known, 1, q{known};
97+
is +Alien::OpenMP::configure->cflags, $omp_flag, q{Found expected OpenMP compiler switch for gcc.};
98+
is +Alien::OpenMP::configure->lddlflags, $omp_flag, q{Found expected OpenMP linker switch for gcc.};
99+
};
100+
89101
subtest 'preprocessor parsing' => sub {
90102
my $result = Alien::OpenMP::configure->version_from_preprocessor(<<'END_OF_CPP');
91103
#define _LP64 1

0 commit comments

Comments
 (0)