Skip to content

Commit

Permalink
Add a test to validate hostfxr C API (#110169)
Browse files Browse the repository at this point in the history
  • Loading branch information
am11 authored and elinor-fung committed Nov 26, 2024
1 parent 6b1ce67 commit dfd8142
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
23 changes: 16 additions & 7 deletions src/native/corehost/hostfxr.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#ifndef __HOSTFXR_H__
#define __HOSTFXR_H__
#ifndef HAVE_HOSTFXR_H
#define HAVE_HOSTFXR_H

#include <stddef.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus

#if defined(_WIN32)
#define HOSTFXR_CALLTYPE __cdecl
#ifdef _WCHAR_T_DEFINED
Expand Down Expand Up @@ -296,10 +301,6 @@ struct hostfxr_dotnet_environment_sdk_info
const char_t* path;
};

typedef void(HOSTFXR_CALLTYPE* hostfxr_get_dotnet_environment_info_result_fn)(
const struct hostfxr_dotnet_environment_info* info,
void* result_context);

struct hostfxr_dotnet_environment_framework_info
{
size_t size;
Expand All @@ -322,6 +323,10 @@ struct hostfxr_dotnet_environment_info
const struct hostfxr_dotnet_environment_framework_info* frameworks;
};

typedef void(HOSTFXR_CALLTYPE* hostfxr_get_dotnet_environment_info_result_fn)(
const struct hostfxr_dotnet_environment_info* info,
void* result_context);

//
// Returns available SDKs and frameworks.
//
Expand Down Expand Up @@ -415,4 +420,8 @@ typedef int32_t(HOSTFXR_CALLTYPE* hostfxr_resolve_frameworks_for_runtime_config_
/*opt*/ hostfxr_resolve_frameworks_result_fn callback,
/*opt*/ void* result_context);

#endif //__HOSTFXR_H__
#ifdef __cplusplus
}
#endif // __cplusplus

#endif // HAVE_HOSTFXR_H
8 changes: 5 additions & 3 deletions src/native/corehost/test/mockhostfxr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Licensed to the .NET Foundation under one or more agreements.
# The .NET Foundation licenses this file to you under the MIT license.

add_library(mockhostfxr_2_2 SHARED mockhostfxr.cpp)
add_library(mockhostfxr_5_0 SHARED mockhostfxr.cpp)
set(MOCKHOSTFXR_SRC mockhostfxr.cpp test_c_api.c)

add_library(mockhostfxr_2_2 SHARED ${MOCKHOSTFXR_SRC})
add_library(mockhostfxr_5_0 SHARED ${MOCKHOSTFXR_SRC})

target_link_libraries(mockhostfxr_2_2 PRIVATE libhostcommon)
target_link_libraries(mockhostfxr_5_0 PRIVATE libhostcommon)
Expand All @@ -11,4 +13,4 @@ target_compile_definitions(mockhostfxr_2_2 PRIVATE MOCKHOSTFXR_2_2 EXPORT_SHARED
target_compile_definitions(mockhostfxr_5_0 PRIVATE MOCKHOSTFXR_5_0 EXPORT_SHARED_API)

install_with_stripped_symbols(mockhostfxr_2_2 TARGETS corehost_test)
install_with_stripped_symbols(mockhostfxr_5_0 TARGETS corehost_test)
install_with_stripped_symbols(mockhostfxr_5_0 TARGETS corehost_test)
3 changes: 3 additions & 0 deletions src/native/corehost/test/mockhostfxr/mockhostfxr.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#include "error_codes.h"
#include "hostfxr.h"
#include "host_startup_info.h"
Expand Down
8 changes: 8 additions & 0 deletions src/native/corehost/test/mockhostfxr/test_c_api.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// hostfxr.h is a public API. When included in .c files, it may fail to compile
// if C++-specific syntax is used within the extern "C" block. Since all usage of
// this API in runtime repo is within C++ code, such breakages are not encountered
// during normal development or testing.
#include "hostfxr.h"

0 comments on commit dfd8142

Please sign in to comment.