Skip to content

Commit

Permalink
[build] A foreign source file can be shared between plasma programs
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulBone committed Aug 21, 2024
1 parent d2ea1b4 commit 03b25aa
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/build.m
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@ not is_empty(DupModules)
find_foreign_sources(Targets, MaybeForeignSources, !DirInfo, !IO),

( MaybeModuleFiles = ok(ModuleFiles),
MaybeForeignSources = ok(ForeignSources),
MaybeForeignSources = ok(ForeignSources0),
ForeignSources = sort_and_remove_dups(ForeignSources0),
ModuleTargets = map(make_module_targets, ModuleFiles),
ProgramTargets = map(make_program_target, Targets),
ForeignLinkTargetsRes = result_list_to_result(map(make_foreign_link_targets, Targets)),
Expand Down
7 changes: 6 additions & 1 deletion tests/ffi/BUILD.plz
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,10 @@ c_sources = [import_from_two_modules.cpp]
[import_two_sources]
type = program
modules = [ImportTwoSources]
c_sources = [import_two_sources.cpp, extra.cpp]
c_sources = [import_two_sources.cpp, import_shared_module.cpp]

[import_shared_module]
type = program
modules = [ImportSharedModule]
c_sources = [import_shared_module.cpp]

2 changes: 1 addition & 1 deletion tests/ffi/extra.cpp → tests/ffi/import_shared_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "../../runtime/pz_foreign.h"
#include "../../runtime/pz_generic_run.h"

#include "extra.h"
#include "import_shared_module.h"

using namespace pz;

Expand Down
6 changes: 3 additions & 3 deletions tests/ffi/extra.h → tests/ffi/import_shared_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* See ../LICENSE.unlicense
*/

#ifndef EXTRA_H
#define EXTRA_H
#ifndef IMPORT_SHARED_MODULE_H
#define IMPORT_SHARED_MODULE_H

unsigned test_extra(void * stack_, unsigned sp);

#endif /* ! EXTRA_H */
#endif /* ! IMPORT_SHARED_MODULE_H */

20 changes: 20 additions & 0 deletions tests/ffi/import_shared_module.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* vim: ft=plasma
* This is free and unencumbered software released into the public domain.
* See ../LICENSE.unlicense
*/

module ImportSharedModule

pragma foreign_include("import_shared_module.h")

func test_extra()
foreign(test_extra)

entrypoint
func test() uses IO -> Int {
test_extra!()

return 0
}

2 changes: 1 addition & 1 deletion tests/ffi/import_two_sources.p
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
module ImportTwoSources

pragma foreign_include("import_two_sources.h")
pragma foreign_include("extra.h")
pragma foreign_include("import_shared_module.h")

func test_a()
foreign(test_a)
Expand Down

0 comments on commit 03b25aa

Please sign in to comment.