Skip to content

feat: shared and static library targets #1138

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

Merged
merged 60 commits into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
7918b56
add `shared` option to the [library] manifest
perazz May 10, 2025
a3dfe13
generalize library name
perazz May 10, 2025
c71301c
on shared library, add per-project library files
perazz May 10, 2025
64257f6
build target: `info` pretty print
perazz May 10, 2025
d5a1314
fix library targets
perazz May 10, 2025
3e83987
exclude empty library files
perazz May 10, 2025
0064295
dependency: add dependency graph to `dependency_node_t`
perazz May 10, 2025
7623c4e
return all dependencies in a manifest
perazz May 10, 2025
cedcf3b
build dependency graph from the manifest
perazz May 10, 2025
faa01a4
remove `package_tmp`
perazz May 11, 2025
b92687b
recurse package dependencies
perazz May 11, 2025
9cf5c7d
localized topological sort for determining the linking order
perazz May 11, 2025
7e78d08
move `library_filename` to fpm_environment
perazz May 11, 2025
7fc19bf
fix order of the link dependencies
perazz May 12, 2025
b374bcb
enumerate shared libraries
perazz May 12, 2025
2ddf082
shared library target linking command
perazz May 12, 2025
5446a2c
compile all libraries separately
perazz May 12, 2025
113ec21
install all lirbary targets
perazz May 12, 2025
fa63aed
[cli] add comments to `fpm new`
perazz May 12, 2025
dd5526b
test: shared lib dependencies
perazz May 12, 2025
fde74e5
test: shared library installer
perazz May 12, 2025
7e7ad82
cleanup
perazz May 12, 2025
32f2aa5
BUGFIX: dev_dependency
perazz May 12, 2025
c27c282
[BUGFIX] ensure target libraries have dependencies among them to ensu…
perazz May 12, 2025
cffc325
add example: shared library with dependencies
perazz May 12, 2025
5beebcd
add shared library examples
perazz May 12, 2025
8c4bfe7
[run] cleanup runner command
perazz May 12, 2025
e6217ed
split get_library_dirs
perazz May 12, 2025
4f4d970
[run] add local library paths to the local environment to ruyn with d…
perazz May 12, 2025
8579677
always run position independent code
perazz May 12, 2025
8bffd89
fix
perazz May 12, 2025
414f448
`requires` (int) -> `package_dep` (string_t)
perazz May 12, 2025
d5f1ecf
do not prune source files when building shared libraries
perazz May 12, 2025
5bf09ea
more shared library tests
perazz May 12, 2025
6e4ff09
Delete .fpm_model.toml.swp
perazz May 12, 2025
49f3710
remove unused variables
perazz May 15, 2025
58f3185
remove `shared`, implement `lib_type` string
perazz May 15, 2025
3b66dc7
replace `library.shared` with `library.type`
perazz May 15, 2025
e57c5da
implement static library linking
perazz May 15, 2025
4ebe231
add static library test
perazz May 15, 2025
7950b0b
line too long
perazz May 15, 2025
c03ceaa
create import library and definition file
perazz May 15, 2025
01fb0b5
export `.def` and import library on Windows
perazz May 15, 2025
db42238
targets: always initialize an output_dir
perazz May 15, 2025
5486d45
ifx bug fix
perazz May 15, 2025
886d609
robust `monolithic` evaluation
perazz May 15, 2025
b0b6d63
fix monolithic source pruning
perazz May 15, 2025
f434cb0
ifx: allocatable string checks
perazz May 15, 2025
9ef7a9e
always prune empty libraries
perazz May 15, 2025
33da9ea
new test: package depends on empty library
perazz May 15, 2025
494564a
new test: package depends on empty library
perazz May 15, 2025
d00e314
add test: enforce dependency ID on pruned empty targets
perazz May 15, 2025
05d09dc
Merge branch 'dynamic_library' of https://github.com/perazz/fpm into …
perazz May 15, 2025
3cd7732
Update fpm_model.f90
perazz May 15, 2025
7d76083
fix failed merge
perazz May 15, 2025
2a47835
do not install `.def` files
perazz May 15, 2025
523c670
Remove accidentally committed binary (bin/fpm)
perazz May 15, 2025
3b5efe5
update CLI help
perazz May 16, 2025
5a795f6
update upstream comment
perazz May 16, 2025
f95cc34
CLI: mention environment variables
perazz May 16, 2025
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ build/*
# CodeBlocks
project/

# Temporary files
*.swp

34 changes: 34 additions & 0 deletions ci/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -310,5 +310,39 @@ fi

popd

# Test shared library dependencies
pushd shared_lib
"$fpm" build || EXIT_CODE=$?
test $EXIT_CODE -eq 0
popd

pushd shared_lib_extra
"$fpm" build || EXIT_CODE=$?
test $EXIT_CODE -eq 0
popd

pushd shared_lib_empty
"$fpm" build
"$fpm" run
"$fpm" test
popd

pushd static_lib_empty
"$fpm" build
"$fpm" run
"$fpm" test
popd

pushd shared_app_only
"$fpm" test || EXIT_CODE=$?
test $EXIT_CODE -eq 0
popd

# Static library dependencies
pushd static_app_only
"$fpm" test || EXIT_CODE=$?
test $EXIT_CODE -eq 0
popd

# Cleanup
rm -rf ./*/build
4 changes: 4 additions & 0 deletions example_packages/shared_app_only/app/main.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
program main
use testdrive
print *, 'Hello, world!'
end program main
8 changes: 8 additions & 0 deletions example_packages/shared_app_only/fpm.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# App only, use shared lib from other folder
name = "shared_app_only"
library.type="shared"
install.library=true
[dependencies]
shared_lib_extra = { path = "../shared_lib_extra" }
[dev-dependencies]
test-drive = { git = "https://github.com/fortran-lang/test-drive", tag="v0.5.0" }
50 changes: 50 additions & 0 deletions example_packages/shared_app_only/test/test.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module test_shared_lib
use testdrive, only : new_unittest, unittest_type, error_type, check
use shared_lib, only: test_something

implicit none

public :: collect


contains

!> Collect all exported unit tests
subroutine collect(testsuite)
!> Collection of tests
type(unittest_type), allocatable, intent(out) :: testsuite(:)

testsuite = [ new_unittest("shared_lib", test_shared) ]

end subroutine collect

subroutine test_shared(error)
type(error_type), allocatable, intent(out) :: error

call check(error, test_something(), 123, "Should be test_something==123")

end subroutine test_shared

end module test_shared_lib

program tester
use, intrinsic :: iso_fortran_env, only : error_unit
use testdrive, only : run_testsuite, new_testsuite, testsuite_type
use test_shared_lib, only : collect
implicit none
integer :: stat
type(testsuite_type), allocatable :: testsuite
character(len=*), parameter :: fmt = '("#", *(1x, a))'

stat = 0

testsuite = new_testsuite("shared_lib", collect)

write(error_unit, fmt) "Testing:", testsuite%name
call run_testsuite(testsuite%collect, error_unit, stat)

if (stat > 0) then
write(error_unit, '(i0, 1x, a)') stat, "test(s) failed!"
error stop
end if
end program tester
3 changes: 3 additions & 0 deletions example_packages/shared_lib/fpm.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Shared library with no executables
name = "shared_lib"
library.type="shared"
14 changes: 14 additions & 0 deletions example_packages/shared_lib/src/shared_lib.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module shared_lib
implicit none
private

public :: say_hello
public :: test_something
contains
subroutine say_hello
print *, "Hello, shared_lib!"
end subroutine say_hello
integer function test_something()
test_something = 123
end function test_something
end module shared_lib
5 changes: 5 additions & 0 deletions example_packages/shared_lib_empty/fpm.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name = "shared_lib_empty"
library.type="shared"
[dependencies]
shared_lib = { path = "../shared_lib" }
shared_app_only = { path = "../shared_app_only" }
4 changes: 4 additions & 0 deletions example_packages/shared_lib_extra/fpm.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name = "shared_lib_extra"
library.type="shared"
[dependencies]
shared_lib = { path = "../shared_lib" }
10 changes: 10 additions & 0 deletions example_packages/shared_lib_extra/src/shared_lib_extra.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module shared_lib_extra
implicit none
private

public :: say_extra_hello
contains
subroutine say_extra_hello
print *, "Hello, shared_lib_extra!"
end subroutine say_extra_hello
end module shared_lib_extra
4 changes: 4 additions & 0 deletions example_packages/static_app_only/app/main.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
program main
use testdrive
print *, 'Hello, world!'
end program main
8 changes: 8 additions & 0 deletions example_packages/static_app_only/fpm.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# App only, use shared libs from other folder, no provided sources
name = "static_app_only"
library.type="static"
install.library=true
[dependencies]
shared_lib_extra = { path = "../shared_lib_extra" }
[dev-dependencies]
test-drive = { git = "https://github.com/fortran-lang/test-drive", tag="v0.5.0" }
50 changes: 50 additions & 0 deletions example_packages/static_app_only/test/test.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module test_shared_lib
use testdrive, only : new_unittest, unittest_type, error_type, check
use shared_lib, only: test_something

implicit none

public :: collect


contains

!> Collect all exported unit tests
subroutine collect(testsuite)
!> Collection of tests
type(unittest_type), allocatable, intent(out) :: testsuite(:)

testsuite = [ new_unittest("shared_lib", test_shared) ]

end subroutine collect

subroutine test_shared(error)
type(error_type), allocatable, intent(out) :: error

call check(error, test_something(), 123, "Should be test_something==123")

end subroutine test_shared

end module test_shared_lib

program tester
use, intrinsic :: iso_fortran_env, only : error_unit
use testdrive, only : run_testsuite, new_testsuite, testsuite_type
use test_shared_lib, only : collect
implicit none
integer :: stat
type(testsuite_type), allocatable :: testsuite
character(len=*), parameter :: fmt = '("#", *(1x, a))'

stat = 0

testsuite = new_testsuite("shared_lib", collect)

write(error_unit, fmt) "Testing:", testsuite%name
call run_testsuite(testsuite%collect, error_unit, stat)

if (stat > 0) then
write(error_unit, '(i0, 1x, a)') stat, "test(s) failed!"
error stop
end if
end program tester
5 changes: 5 additions & 0 deletions example_packages/static_lib_empty/fpm.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name = "static_lib_empty"
library.type="static"
[dependencies]
shared_lib = { path = "../shared_lib" }
shared_app_only = { path = "../shared_app_only" }
Loading
Loading