Skip to content
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

Merged
23 commits merged into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4841c9a
hostfxr: Build most of hostfxr as a static library
lpereira Apr 16, 2020
4c89d2c
hostpolicy: Build as a static library
lpereira Apr 16, 2020
d942cf2
corehost: Allow linking of hostfxr and hostpolicy with apphost
lpereira Apr 16, 2020
ea2b6d7
dotnet: Teach the muxer binary about hostfxr_iface
lpereira Apr 16, 2020
0f8daea
apphost: Teach apphost about hostfxr_iface
lpereira Apr 16, 2020
23f1bf9
Add exports for hostfxr and policy
VSadov Apr 23, 2020
54506ae
Exports for unix
VSadov Apr 24, 2020
87a4e1f
EXPORTS_LINKER_OPTION
VSadov Apr 24, 2020
a8b90ae
use generateversionscript.awk from ENG
VSadov Apr 24, 2020
b231629
Move fxr files out of static
VSadov Apr 24, 2020
1efc302
Fixes for Linux
VSadov Apr 27, 2020
d381ab4
Fix for win-x86
VSadov Apr 27, 2020
50d6cd6
move HEADERS next to SOURCES similarly to other files.
VSadov Apr 27, 2020
b9cd86a
PR feedback (simplifying hostpolicy_resolver::try_get_dir for static …
VSadov Apr 27, 2020
433db23
Publish static_apphost to Microsoft.NETCore.App.Host
VSadov Apr 27, 2020
8e91d89
bind to entry points without probing, when in a static host.
VSadov May 1, 2020
444cd0a
Add a test case
swaroop-sridhar May 4, 2020
8f3de42
Merge pull request #2 from swaroop-sridhar/staticHostTest
VSadov May 5, 2020
818f5c6
renamed hostfxr_iface --> hostfxr_resolver_t
VSadov May 5, 2020
d95d0ca
renamed shared --> standalone
VSadov May 5, 2020
67cf394
rename static_apphost --> singlefilehost
VSadov May 5, 2020
eb30f92
Signing exclusions for singlefilehost
VSadov May 5, 2020
8669c80
switched StaticHost tst to a different asset (mostly a copy of Standa…
VSadov May 5, 2020
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
1 change: 1 addition & 0 deletions eng/SignCheckExclusionsFile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
;; and SCD apps. If they are signed, the file that the SDK produces has an invalid signature and
;; can't be signed again. More info at https://github.com/dotnet/core-setup/pull/7549.
*apphost.exe;;Template, https://github.com/dotnet/core-setup/pull/7549
*static_apphost.exe;;Template, https://github.com/dotnet/core-setup/pull/7549
*comhost.dll;;Template, https://github.com/dotnet/core-setup/pull/7549
*apphosttemplateapphostexe.exe;;Template, https://github.com/dotnet/core-setup/pull/7549
*comhosttemplatecomhostdll.dll;;Template, https://github.com/dotnet/core-setup/pull/7549
2 changes: 1 addition & 1 deletion eng/Signing.props
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<BundleInstallerExeArtifact Include="$(ArtifactsPackagesDir)**/*.exe" />

<!-- apphost and comhost template files are not signed, by design. -->
<FileSignInfo Include="apphost.exe;comhost.dll" CertificateName="None" />
<FileSignInfo Include="apphost.exe;static_apphost.exe;comhost.dll" CertificateName="None" />
</ItemGroup>

<ItemGroup Condition="'$(CrossTargetComponentFolder)' != ''">
Expand Down
8 changes: 4 additions & 4 deletions eng/native/functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ function(generate_exports_file)

add_custom_command(
OUTPUT ${outputFilename}
COMMAND ${AWK} -f ${CMAKE_SOURCE_DIR}/${AWK_SCRIPT} ${INPUT_LIST} >${outputFilename}
DEPENDS ${INPUT_LIST} ${CMAKE_SOURCE_DIR}/${AWK_SCRIPT}
COMMAND ${AWK} -f ${CLR_ENG_NATIVE_DIR}/${AWK_SCRIPT} ${INPUT_LIST} >${outputFilename}
DEPENDS ${INPUT_LIST} ${CLR_ENG_NATIVE_DIR}/${AWK_SCRIPT}
COMMENT "Generating exports file ${outputFilename}"
)
set_source_files_properties(${outputFilename}
Expand All @@ -196,8 +196,8 @@ function(generate_exports_file_prefix inputFilename outputFilename prefix)

add_custom_command(
OUTPUT ${outputFilename}
COMMAND ${AWK} -f ${CMAKE_SOURCE_DIR}/${AWK_SCRIPT} ${AWK_VARS} ${inputFilename} >${outputFilename}
DEPENDS ${inputFilename} ${CMAKE_SOURCE_DIR}/${AWK_SCRIPT}
COMMAND ${AWK} -f ${CLR_ENG_NATIVE_DIR}/${AWK_SCRIPT} ${AWK_VARS} ${inputFilename} >${outputFilename}
DEPENDS ${inputFilename} ${CLR_ENG_NATIVE_DIR}/${AWK_SCRIPT}
COMMENT "Generating exports file ${outputFilename}"
)
set_source_files_properties(${outputFilename}
Expand Down
4 changes: 2 additions & 2 deletions src/installer/corehost/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
add_subdirectory(hostcommon)
add_subdirectory(apphost)
add_subdirectory(dotnet)
add_subdirectory(fxr)
add_subdirectory(hostpolicy)
add_subdirectory(nethost)
add_subdirectory(test_fx_ver)
add_subdirectory(fxr)
add_subdirectory(hostpolicy)

add_subdirectory(test)

Expand Down
48 changes: 2 additions & 46 deletions src/installer/corehost/cli/apphost/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,5 @@
# 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)

set(SOURCES
./bundle_marker.cpp
)

set(HEADERS
./bundle_marker.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()
add_subdirectory(static)
Copy link
Contributor

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.

Copy link
Member Author

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"?

Copy link
Contributor

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.

Copy link
Member Author

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)

add_subdirectory(shared)
54 changes: 54 additions & 0 deletions src/installer/corehost/cli/apphost/shared/CMakeLists.txt
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 src/installer/corehost/cli/apphost/shared/hostfxr_iface.cpp
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);
}
}
63 changes: 63 additions & 0 deletions src/installer/corehost/cli/apphost/static/CMakeLists.txt
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@richlander @samsp-msft
Wanted to ask again if we want a better name for the static host, instead of static_apphost.exe?

We build two types of hosts:

  • Apphost linked with other host components code-named "static apphost" (this PR) -- this will ship in the Microsoft.netcoreapp.host package for Windows (and Mac).
  • Apphost linked with host and runtime components code-named "super apphost" (TBD) -- this will ship in the Microsoft.netcoreapp.host package for Linux.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VSadov please see @jkotas comments here: #32823 (comment).
This static_apphost should be renamed to netcoreapphost or singlefilehost

Copy link
Member Author

Choose a reason for hiding this comment

The 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.
singleapphost feels a bit better as it hints at the purpose of the file.
I assume the standalone apphost will not be used (or will not be recommended) for single-file scenarios once this is shipped.

I will change to singleapphost.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The feature is called SingleFile (e.g. -p:PublishSingleFile=true) so the name should be singlefile* for consistency.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

singlefilehost ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I meant singlefilehost in the first place.

singleapphost was a mistype.

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
)
63 changes: 63 additions & 0 deletions src/installer/corehost/cli/apphost/static/hostfxr_iface.cpp
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()
{
}
Loading