| 608 | } |
| 609 | |
| 610 | SC::Result SC::PluginCompiler::link(const PluginDefinition& definition, const PluginSysroot& sysroot, |
| 611 | const PluginCompilerEnvironment& compilerEnvironment, StringSpan executablePath, |
| 612 | Span<char>& linkerLog) const |
| 613 | { |
| 614 | static constexpr size_t MAX_PROCESS_ARGUMENTS = 24; |
| 615 | |
| 616 | size_t numberOfStrings = 0; |
| 617 | size_t stringLengths[MAX_PROCESS_ARGUMENTS]; |
| 618 | |
| 619 | StringSpan::NativeWritable bufferWritable = {buffer}; |
| 620 | |
| 621 | StringsArena arena = {bufferWritable, numberOfStrings, {stringLengths}}; |
| 622 | SC_TRY_MSG(arena.appendAsSingleString({linkerPath.view()}), "link buffer full"); |
| 623 | |
| 624 | #if SC_PLATFORM_WINDOWS |
| 625 | (void)(compilerEnvironment); |
| 626 | |
| 627 | if (not definition.build.contains("libc") and not definition.build.contains("libc++")) |
| 628 | { |
| 629 | SC_TRY(arena.appendMultipleStrings({SC_NATIVE_STR("/NODEFAULTLIB"), SC_NATIVE_STR("/ENTRY:DllMain")})); |
| 630 | } |
| 631 | SC_TRY(arena.appendMultipleStrings( |
| 632 | {SC_NATIVE_STR("/nologo"), SC_NATIVE_STR("/DLL"), SC_NATIVE_STR("/DEBUG"), SC_NATIVE_STR("/SAFESEH:NO")})); |
| 633 | |
| 634 | for (size_t idx = 0; idx < compilerLibraryPaths.size(); ++idx) |
| 635 | { |
| 636 | SC_TRY(arena.appendAsSingleString({SC_NATIVE_STR("/LIBPATH:"), compilerLibraryPaths[idx].view()})); |
| 637 | } |
| 638 | |
| 639 | for (size_t idx = 0; idx < sysroot.libraryPaths.size(); ++idx) |
| 640 | { |
| 641 | SC_TRY(arena.appendAsSingleString({SC_NATIVE_STR("/LIBPATH:"), sysroot.libraryPaths[idx].view()})); |
| 642 | } |
| 643 | |
| 644 | SC_TRY(arena.appendAsSingleString({SC_NATIVE_STR("/LIBPATH:"), PluginString::dirname(executablePath)})); |
| 645 | |
| 646 | StringSpan exeName = PluginString::basename(executablePath, SC_NATIVE_STR(".exe")); |
| 647 | SC_TRY(arena.appendAsSingleString({exeName, SC_NATIVE_STR(".lib")})); |
| 648 | |
| 649 | #else |
| 650 | (void)(sysroot); |
| 651 | SC_TRY(arena.appendMultipleStrings({"-fpic"})); |
| 652 | |
| 653 | if (not sysroot.isysroot.isEmpty()) |
| 654 | { |
| 655 | SC_TRY(arena.appendMultipleStrings({"-isysroot", sysroot.isysroot.view()})); |
| 656 | } |
| 657 | SC_TRY(PluginCompilerEnvironment::Internal::writeFlags(compilerEnvironment.ldFlags, arena)); |
| 658 | |
| 659 | // TODO: Figure out where to link _memcpy & co when using -nostdlib |
| 660 | |
| 661 | if (type == Type::ClangCompiler) |
| 662 | { |
| 663 | if (not definition.build.contains("libc++")) |
| 664 | { |
| 665 | SC_TRY(arena.appendMultipleStrings({"-nostdlib++"})); |
| 666 | } |
| 667 | } |
no test coverage detected