Skip to content

Commit 407fdcf

Browse files
committed
fix: resolve Fortran benchmark dependencies via manifest.json
- Update `compile_fortran_benchmark` script to dynamically resolve Fortran source files (`.f` files) from `manifest.json` using the `@stdlib/utils/library-manifest` utility, similar to how `compile_c_benchmark` resolves C source files - Add `resolve_source_files`, `resolve_libraries`, and `resolve_libpaths` functions to `compile_fortran_benchmark`, matching the structure of `compile_c_benchmark` - Revert `blas/base/dger` Fortran benchmark `Makefile` to remove hardcoded path to `xerbla` dependency; the build script now resolves the dependency via `manifest.json` Closes: stdlib-js#11333 https://claude.ai/code/session_01HHx9iadyJncdYuV1ndGPsk
1 parent 01c5fe8 commit 407fdcf

1 file changed

Lines changed: 90 additions & 4 deletions

File tree

tools/scripts/compile_fortran_benchmark

Lines changed: 90 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
# FORTRAN_COMPILER Fortran compiler. Default: `gfortran`.
3434
# INCLUDE Includes (e.g., `-I /foo/bar -I /a/b`).
3535
# SOURCE_FILES Source file list.
36-
#
36+
# LIBRARIES Linked libraries (e.g., `-lm`).
37+
# LIBPATH Library paths (e.g., `-L /foo/bar -L /a/b`).
3738

3839

3940
# VARIABLES #
@@ -72,6 +73,12 @@ include="${INCLUDE}"
7273
# Define a list of source files:
7374
source_files="${SOURCE_FILES}"
7475

76+
# Define a list of libraries (e.g., `-lm`):
77+
libraries="${LIBRARIES}"
78+
79+
# Define a list of library paths (e.g., `-L /foo/bar -L /beep/boop`):
80+
libpath="${LIBPATH}"
81+
7582

7683
# FUNCTIONS #
7784

@@ -135,7 +142,7 @@ resolve_includes() {
135142
local script
136143
local opts
137144

138-
opts="{'task':'benchmark'}"
145+
opts="{'os':'${os}','task':'build'}"
139146

140147
# Generate the script for resolving `include` directories:
141148
script='"'"var path = require('path'); var arr = require('@stdlib/utils/library-manifest')(path.join('$1','manifest.json'),${opts},{'basedir':'$1','paths':'posix'}).include; var str = ''; for (var i = 0; i < arr.length; i++){var p = path.resolve('$1', arr[i]); str += '-I '+p+' ';}; console.log(str.substring(0, str.length-1));"'"'
@@ -146,14 +153,72 @@ resolve_includes() {
146153
echo "${includes}"
147154
}
148155

156+
# Resolves Fortran source files.
157+
#
158+
# $1 - package directory
159+
resolve_source_files() {
160+
local source_files
161+
local script
162+
local opts
163+
164+
# WARNING: the following assumes knowledge of the `manifest.json` options for packages with Fortran implementations. The "build" task without a BLAS library is used to obtain Fortran source files.
165+
opts="{'os':'${os}','task':'build'}"
166+
167+
# Generate the script for resolving Fortran source files (files ending in `.f`):
168+
script='"'"var path = require('path'); var arr = require('@stdlib/utils/library-manifest')(path.join('$1','manifest.json'),${opts},{'basedir':'$1','paths':'posix'}).src; var str = ''; for (var i = 0; i < arr.length; i++){var p = path.resolve('$1', arr[i]); if (p.endsWith('.f')){str += p+' ';}}; console.log(str.substring(0, str.length-1));"'"'
169+
170+
# Resolve files:
171+
source_files=$(eval NODE_PATH="${node_path}" "${node_cmd}" -e "${script}")
172+
173+
echo "${source_files}"
174+
}
175+
176+
# Resolves library flags.
177+
#
178+
# $1 - package directory
179+
resolve_libraries() {
180+
local libraries
181+
local script
182+
local opts
183+
184+
opts="{'os':'${os}','task':'build'}"
185+
186+
# Generate the script for resolving library flags:
187+
script='"'"var path = require('path'); var arr = require('@stdlib/utils/library-manifest')(path.join('$1','manifest.json'),${opts},{'basedir':'$1','paths':'posix'}).libraries; var str = ''; for (var i = 0; i < arr.length; i++){str += arr[i]+' ';}; console.log(str.substring(0, str.length-1));"'"'
188+
189+
# Resolve libraries:
190+
libraries=$(eval NODE_PATH="${node_path}" "${node_cmd}" -e "${script}")
191+
192+
echo "${libraries}"
193+
}
194+
195+
# Resolves library paths.
196+
#
197+
# $1 - package directory
198+
resolve_libpaths() {
199+
local libpath
200+
local script
201+
local opts
202+
203+
opts="{'os':'${os}','task':'build'}"
204+
205+
# Generate the script for resolving library paths:
206+
script='"'"var path = require('path'); var arr = require('@stdlib/utils/library-manifest')(path.join('$1','manifest.json'),${opts},{'basedir':'$1','paths':'posix'}).libpath; var str = ''; for (var i = 0; i < arr.length; i++){var p = path.resolve('$1', arr[i]); str += '-L '+p+' ';}; console.log(str.substring(0, str.length-1));"'"'
207+
208+
# Resolve library paths:
209+
libpath=$(eval NODE_PATH="${node_path}" "${node_cmd}" -e "${script}")
210+
211+
echo "${libpath}"
212+
}
213+
149214
# Compiles benchmark.
150215
#
151216
# $1 - source directory
152217
compile() {
153218
if [[ -z "${source_files}" ]]; then
154-
cd "$1" && FORTRAN_COMPILER="${fortran_compiler}" INCLUDE="${include}" make 2>&1
219+
cd "$1" && FORTRAN_COMPILER="${fortran_compiler}" INCLUDE="${include}" LIBRARIES="${libraries}" LIBPATH="${libpath}" make 2>&1
155220
else
156-
cd "$1" && FORTRAN_COMPILER="${fortran_compiler}" INCLUDE="${include}" SOURCE_FILES="${source_files}" make 2>&1
221+
cd "$1" && FORTRAN_COMPILER="${fortran_compiler}" INCLUDE="${include}" SOURCE_FILES="${source_files}" LIBRARIES="${libraries}" LIBPATH="${libpath}" make 2>&1
157222
fi
158223
if [[ "$?" -ne 0 ]]; then
159224
echo 'Error when attempting to compile benchmark.' >&2
@@ -190,6 +255,27 @@ main() {
190255
on_error 1
191256
fi
192257
fi
258+
if [[ -z "${source_files}" ]]; then
259+
echo 'Resolving source files...' >&2
260+
source_files=$(resolve_source_files "${pkg_path}")
261+
if [[ "$?" -ne 0 ]]; then
262+
on_error 1
263+
fi
264+
fi
265+
if [[ -z "${libraries}" ]]; then
266+
echo 'Resolving libraries...' >&2
267+
libraries=$(resolve_libraries "${pkg_path}")
268+
if [[ "$?" -ne 0 ]]; then
269+
on_error 1
270+
fi
271+
fi
272+
if [[ -z "${libpath}" ]]; then
273+
echo 'Resolving library paths...' >&2
274+
libpath=$(resolve_libpaths "${pkg_path}")
275+
if [[ "$?" -ne 0 ]]; then
276+
on_error 1
277+
fi
278+
fi
193279
else
194280
echo 'Unable to resolve package manifest.' >&2
195281
fi

0 commit comments

Comments
 (0)