-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Build an apphost with hostfxr and hostpolicy linked in #35087
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ff2d127
hostfxr: Build most of hostfxr as a static library
lpereira 06fc021
hostpolicy: Build as a static library
lpereira 3866534
corehost: Allow linking of hostfxr and hostpolicy with apphost
lpereira df43b0e
dotnet: Teach the muxer binary about hostfxr_iface
lpereira 69687f8
apphost: Teach apphost about hostfxr_iface
lpereira File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # Licensed to the .NET Foundation under one or more agreements. | ||
| # The .NET Foundation licenses this file to you under the MIT license. | ||
| # See the LICENSE file in the project root for more information. | ||
|
|
||
| project(apphost) | ||
| set(DOTNET_PROJECT_NAME "apphost") | ||
|
|
||
| # Add RPATH to the apphost binary that allows using local copies of shared libraries | ||
| # dotnet core depends on for special scenarios when system wide installation of such | ||
| # dependencies is not possible for some reason. | ||
| # This cannot be enabled for MacOS (Darwin) since its RPATH works in a different way, | ||
| # doesn't apply to libraries loaded via dlopen and most importantly, it is not transitive. | ||
| if (NOT CLR_CMAKE_TARGET_OSX) | ||
| set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) | ||
| set(CMAKE_INSTALL_RPATH "\$ORIGIN/netcoredeps") | ||
| endif() | ||
|
|
||
| set(SKIP_VERSIONING 1) | ||
|
|
||
| include_directories(..) | ||
|
|
||
| set(SOURCES | ||
| ../bundle_marker.cpp | ||
| ./hostfxr_iface.cpp | ||
| ) | ||
|
|
||
| set(HEADERS | ||
| ../bundle_marker.h | ||
| ../../../hostfxr_iface.h | ||
| ) | ||
|
|
||
| if(CLR_CMAKE_TARGET_WIN32) | ||
| list(APPEND SOURCES | ||
| ../apphost.windows.cpp) | ||
|
|
||
| list(APPEND HEADERS | ||
| ../apphost.windows.h) | ||
| endif() | ||
|
|
||
| include(../../exe.cmake) | ||
|
|
||
| add_definitions(-DFEATURE_APPHOST=1) | ||
|
|
||
| # Disable manifest generation into the file .exe on Windows | ||
| if(CLR_CMAKE_TARGET_WIN32) | ||
| set_property(TARGET ${PROJECT_NAME} PROPERTY | ||
| LINK_FLAGS "/MANIFEST:NO" | ||
| ) | ||
| endif() | ||
|
|
||
| # Specify non-default Windows libs to be used for Arm/Arm64 builds | ||
| if (CLR_CMAKE_TARGET_WIN32 AND (CLR_CMAKE_TARGET_ARCH_ARM OR CLR_CMAKE_TARGET_ARCH_ARM64)) | ||
| target_link_libraries(apphost Advapi32.lib shell32.lib) | ||
| endif() |
61 changes: 61 additions & 0 deletions
61
src/installer/corehost/cli/apphost/shared/hostfxr_iface.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| #include <assert.h> | ||
|
|
||
| #include "pal.h" | ||
| #include "fxr_resolver.h" | ||
| #include "trace.h" | ||
| #include "hostfxr_iface.h" | ||
|
|
||
| hostfxr_main_bundle_startupinfo_fn hostfxr::resolve_main_bundle_startupinfo() | ||
| { | ||
| assert(m_hostfxr_dll != nullptr); | ||
| return reinterpret_cast<hostfxr_main_bundle_startupinfo_fn>(pal::get_symbol(m_hostfxr_dll, "hostfxr_main_bundle_startupinfo")); | ||
| } | ||
|
|
||
| hostfxr_set_error_writer_fn hostfxr::resolve_set_error_writer() | ||
| { | ||
| assert(m_hostfxr_dll != nullptr); | ||
| return reinterpret_cast<hostfxr_set_error_writer_fn>(pal::get_symbol(m_hostfxr_dll, "hostfxr_set_error_writer")); | ||
| } | ||
|
|
||
| hostfxr_main_startupinfo_fn hostfxr::resolve_main_startupinfo() | ||
| { | ||
| assert(m_hostfxr_dll != nullptr); | ||
| return reinterpret_cast<hostfxr_main_startupinfo_fn>(pal::get_symbol(m_hostfxr_dll, "hostfxr_main_startupinfo")); | ||
| } | ||
|
|
||
| hostfxr_main_fn hostfxr::resolve_main_v1() | ||
| { | ||
| assert(m_hostfxr_dll != nullptr); | ||
| return reinterpret_cast<hostfxr_main_fn>(pal::get_symbol(m_hostfxr_dll, "hostfxr_main")); | ||
| } | ||
|
|
||
| hostfxr::hostfxr(const pal::string_t& app_root) | ||
| { | ||
| if (!fxr_resolver::try_get_path(app_root, &m_dotnet_root, &m_fxr_path)) | ||
| { | ||
| m_status_code = StatusCode::CoreHostLibMissingFailure; | ||
| } | ||
| else if (pal::load_library(&m_fxr_path, &m_hostfxr_dll)) | ||
| { | ||
| m_status_code = StatusCode::Success; | ||
| } | ||
| else | ||
| { | ||
| trace::error(_X("The library %s was found, but loading it from %s failed"), LIBFXR_NAME, m_fxr_path.c_str()); | ||
| trace::error(_X(" - Installing .NET prerequisites might help resolve this problem.")); | ||
| trace::error(_X(" %s"), DOTNET_CORE_INSTALL_PREREQUISITES_URL); | ||
| m_status_code = StatusCode::CoreHostLibLoadFailure; | ||
| } | ||
| } | ||
|
|
||
| hostfxr::~hostfxr() | ||
| { | ||
| if (m_hostfxr_dll != nullptr) | ||
| { | ||
| pal::unload_library(m_hostfxr_dll); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # Licensed to the .NET Foundation under one or more agreements. | ||
| # The .NET Foundation licenses this file to you under the MIT license. | ||
| # See the LICENSE file in the project root for more information. | ||
|
|
||
| project(static_apphost) | ||
| set(DOTNET_PROJECT_NAME "static_apphost") | ||
|
|
||
| # Add RPATH to the apphost binary that allows using local copies of shared libraries | ||
| # dotnet core depends on for special scenarios when system wide installation of such | ||
| # dependencies is not possible for some reason. | ||
| # This cannot be enabled for MacOS (Darwin) since its RPATH works in a different way, | ||
| # doesn't apply to libraries loaded via dlopen and most importantly, it is not transitive. | ||
| if (NOT CLR_CMAKE_TARGET_OSX) | ||
| set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) | ||
| set(CMAKE_INSTALL_RPATH "\$ORIGIN/netcoredeps") | ||
| endif() | ||
|
|
||
| set(SKIP_VERSIONING 1) | ||
|
|
||
| include_directories(..) | ||
|
|
||
| set(SOURCES | ||
| ../bundle_marker.cpp | ||
| ./hostfxr_iface.cpp | ||
| ) | ||
|
|
||
| set(HEADERS | ||
| ../bundle_marker.h | ||
| ../../../hostfxr_iface.h | ||
| ) | ||
|
|
||
| if(CLR_CMAKE_TARGET_WIN32) | ||
| list(APPEND SOURCES | ||
| ../apphost.windows.cpp) | ||
|
|
||
| list(APPEND HEADERS | ||
| ../apphost.windows.h) | ||
| endif() | ||
|
|
||
| include(../../exe.cmake) | ||
|
|
||
| add_definitions(-DFEATURE_APPHOST=1) | ||
| add_definitions(-DFEATURE_STATIC_HOST=1) | ||
|
|
||
| # Disable manifest generation into the file .exe on Windows | ||
| if(CLR_CMAKE_TARGET_WIN32) | ||
| set_property(TARGET ${PROJECT_NAME} PROPERTY | ||
| LINK_FLAGS "/MANIFEST:NO" | ||
| ) | ||
| endif() | ||
|
|
||
| # Specify non-default Windows libs to be used for Arm/Arm64 builds | ||
| if (CLR_CMAKE_TARGET_WIN32 AND (CLR_CMAKE_TARGET_ARCH_ARM OR CLR_CMAKE_TARGET_ARCH_ARM64)) | ||
| target_link_libraries(static_apphost Advapi32.lib shell32.lib) | ||
| endif() | ||
|
|
||
| target_link_libraries(static_apphost | ||
| libhostfxr_static | ||
| libhostpolicy_static | ||
| libhostcommon | ||
| ) |
63 changes: 63 additions & 0 deletions
63
src/installer/corehost/cli/apphost/static/hostfxr_iface.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| #include <assert.h> | ||
| #include "trace.h" | ||
| #include "hostfxr.h" | ||
| #include "hostfxr_iface.h" | ||
|
|
||
| extern "C" | ||
| { | ||
| int HOSTFXR_CALLTYPE hostfxr_main_bundle_startupinfo(const int argc, const pal::char_t* argv[], const pal::char_t* host_path, const pal::char_t* dotnet_root, const pal::char_t* app_path, int64_t bundle_header_offset); | ||
| int HOSTFXR_CALLTYPE hostfxr_main_startupinfo(const int argc, const pal::char_t* argv[], const pal::char_t* host_path, const pal::char_t* dotnet_root, const pal::char_t* app_path); | ||
| int HOSTFXR_CALLTYPE hostfxr_main(const int argc, const pal::char_t* argv[]); | ||
| hostfxr_error_writer_fn HOSTFXR_CALLTYPE hostfxr_set_error_writer(hostfxr_error_writer_fn error_writer); | ||
| } | ||
|
|
||
| hostfxr_main_bundle_startupinfo_fn hostfxr::resolve_main_bundle_startupinfo() | ||
| { | ||
| assert(m_hostfxr_dll == nullptr); | ||
| return hostfxr_main_bundle_startupinfo; | ||
| } | ||
|
|
||
| hostfxr_set_error_writer_fn hostfxr::resolve_set_error_writer() | ||
| { | ||
| assert(m_hostfxr_dll == nullptr); | ||
| return hostfxr_set_error_writer; | ||
| } | ||
|
|
||
| hostfxr_main_startupinfo_fn hostfxr::resolve_main_startupinfo() | ||
| { | ||
| assert(m_hostfxr_dll == nullptr); | ||
| return hostfxr_main_startupinfo; | ||
| } | ||
|
|
||
| hostfxr_main_fn hostfxr::resolve_main_v1() | ||
| { | ||
| assert(m_hostfxr_dll == nullptr); | ||
| assert(!"This function should not be called in a static host"); | ||
| return nullptr; | ||
| } | ||
|
|
||
| hostfxr::hostfxr(const pal::string_t& app_root) | ||
| { | ||
| if (app_root.length() == 0) | ||
| { | ||
| trace::info(_X("Application root path is empty. This shouldn't happen")); | ||
| m_status_code = StatusCode::CoreHostLibMissingFailure; | ||
| } | ||
| else | ||
| { | ||
| trace::info(_X("Using internal fxr")); | ||
|
|
||
| m_dotnet_root.assign(app_root); | ||
| m_fxr_path.assign(app_root); | ||
|
|
||
| m_status_code = StatusCode::Success; | ||
| } | ||
| } | ||
|
|
||
| hostfxr::~hostfxr() | ||
| { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.