-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Build an apphost with hostfxr and hostpolicy linked in #35368
Changes from 16 commits
4841c9a
4c89d2c
d942cf2
ea2b6d7
0f8daea
23f1bf9
54506ae
87a4e1f
a8b90ae
b231629
1efc302
d381ab4
50d6cd6
b9cd86a
433db23
8e91d89
444cd0a
8f3de42
818f5c6
d95d0ca
67cf394
eb30f92
8669c80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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() |
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); | ||
} | ||
} |
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. | ||
|
||
project(static_apphost) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @richlander @samsp-msft We build two types of hosts:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @VSadov please see @jkotas comments here: #32823 (comment). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The file is a template to be linked with app parts and renamed, so naming is not extremely important IMO. I will change to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The feature is called SingleFile (e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I meant
|
||
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(..) | ||
include_directories(../../json) | ||
|
||
set(SOURCES | ||
../bundle_marker.cpp | ||
./hostfxr_iface.cpp | ||
./hostpolicy_resolver.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 | ||
) |
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() | ||
{ | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure "static" and "shared" are the best names here.
I think Leandro chose these because of static and shared libraries.
But "shared" is a bit confusing because (a) it seems to represent code shared between different kinds of builds, and (b) apphost is not a shared library.
Please consider renaming them to more representative names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not like 'shared', but did not have a lot of good alternatives. It is an opposite of "static" and "super" - could it be "standalone"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I think "standalone" is a good option. "linked vs standalone" or "static vs standalone" are good I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will make it static vs. standalone. (static seems good enough)