Skip to content

Commit 2e8702e

Browse files
committed
- split browserhost into libBrowserHost.a, so that it could be linked later on customer machine
- make browserhost dependent on .a files of `libs.native+clr.runtime` subsets, instaed of CMake target and sub_direcotry
1 parent d3615fa commit 2e8702e

File tree

9 files changed

+101
-46
lines changed

9 files changed

+101
-46
lines changed

src/native/corehost/browserhost/CMakeLists.txt

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,8 @@
44
project(browserhost)
55
set(DOTNET_PROJECT_NAME "browserhost")
66

7-
configure_file(${CLR_SRC_NATIVE_DIR}/corehost/configure.h.in ${GENERATED_INCLUDE_DIR}/corehost/configure.h)
8-
target_include_directories(hostmisc_interface INTERFACE ${GENERATED_INCLUDE_DIR}/corehost)
9-
10-
set(SOURCES
11-
./browserhost.cpp
12-
native.rc
7+
set(BROWSERHOST_SOURCES
8+
empty.c
139
)
1410
set(HEADERS
1511
)
@@ -18,47 +14,44 @@ add_compile_definitions(FEATURE_APPHOST)
1814
add_definitions(-DFEATURE_APPHOST=1)
1915
add_definitions(-DFEATURE_STATIC_HOST=1)
2016

21-
add_executable(browserhost ${SOURCES})
17+
add_executable(browserhost ${BROWSERHOST_SOURCES})
2218
set_target_properties(browserhost PROPERTIES OUTPUT_NAME dotnet.native)
2319
set(CMAKE_EXECUTABLE_SUFFIX ".js")
24-
add_dependencies(browserhost System.Native.Browser-Rollup)
25-
add_dependencies(browserhost System.Native.Browser-Static)
26-
add_dependencies(browserhost System.Runtime.InteropServices.JavaScript.Native-Static)
2720

28-
install(TARGETS browserhost DESTINATION corehost COMPONENT runtime)
29-
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/dotnet.native.wasm DESTINATION corehost COMPONENT runtime)
21+
add_subdirectory(lib-browserhost)
22+
add_dependencies(browserhost BrowserHost-Static)
3023

31-
include(configure.cmake)
24+
set(STATIC_LIB_DESTINATION
25+
${CLR_ARTIFACTS_BIN_DIR}/native/net${CMAKE_NET_CORE_APP_CURRENT_VERSION}-browser-${CMAKE_BUILD_TYPE}-wasm/)
26+
set(STATIC_CLR_DESTINATION
27+
${CLR_ARTIFACTS_BIN_DIR}/coreclr/browser.wasm.${CMAKE_BUILD_TYPE}/)
3228

29+
# these dependencies assume that you built `libs.native+clr.runtime` subsets first
3330
LIST(APPEND NATIVE_LIBS
34-
coreclr_static
35-
System.Native.Browser-Static
36-
System.Runtime.InteropServices.JavaScript.Native-Static
37-
System.Native-Static
38-
System.Globalization.Native-Static
39-
System.IO.Compression.Native-Static
40-
nativeresourcestring
41-
gcinfo
31+
${STATIC_CLR_DESTINATION}/libcoreclr_static.a
32+
${STATIC_CLR_DESTINATION}/libclrinterpreter.a
33+
${STATIC_CLR_DESTINATION}/lib/libnativeresourcestring.a
34+
${STATIC_CLR_DESTINATION}/gcinfo/libgcinfo_unix_wasm.a
35+
${STATIC_LIB_DESTINATION}/libSystem.Native.Browser.a
36+
${STATIC_LIB_DESTINATION}/libSystem.Runtime.InteropServices.JavaScript.Native.a
37+
${STATIC_LIB_DESTINATION}/libSystem.Native.a
38+
${STATIC_LIB_DESTINATION}/libSystem.Globalization.Native.a
39+
${STATIC_LIB_DESTINATION}/libSystem.IO.Compression.Native.a
4240
# WASM-TODO respect $(InvariantTimezone)
43-
# System.Native.TimeZoneData.Invariant
44-
System.Native.TimeZoneData
41+
# libSystem.Native.TimeZoneData.Invariant.a
42+
${STATIC_LIB_DESTINATION}/libSystem.Native.TimeZoneData.a
4543
)
4644

47-
# WASM-TODO set(RUNTIMEINFO_LIB runtimeinfo)
48-
49-
target_compile_options(browserhost PRIVATE
50-
-fwasm-exceptions
51-
-msimd128
52-
)
53-
45+
set(NATIVE_JAVASCRIPT_BIN
46+
${CLR_ARTIFACTS_BIN_DIR}/native/net${CMAKE_NET_CORE_APP_CURRENT_VERSION}-browser-${CMAKE_BUILD_TYPE}-wasm/)
5447
set(JS_SYSTEM_NATIVE_BROWSER
55-
"${CLR_ARTIFACTS_OBJ_DIR}/native/browser-${CMAKE_BUILD_TYPE}-wasm/System.Native.Browser/libSystem.Native.Browser.js")
48+
"${NATIVE_JAVASCRIPT_BIN}/libSystem.Native.Browser.js")
5649
set(JS_SYSTEM_BROWSER_UTILS
57-
"${CLR_ARTIFACTS_OBJ_DIR}/native/browser-${CMAKE_BUILD_TYPE}-wasm/System.Native.Browser/libSystem.Browser.Utils.js")
50+
"${NATIVE_JAVASCRIPT_BIN}/libSystem.Browser.Utils.js")
5851
set(JS_SYSTEM_RUNTIME_INTEROPSERVICES_JAVASCRIPT_NATIVE
59-
"${CLR_ARTIFACTS_OBJ_DIR}/native/browser-${CMAKE_BUILD_TYPE}-wasm/System.Runtime.InteropServices.JavaScript.Native/libSystem.Runtime.InteropServices.JavaScript.Native.js")
52+
"${NATIVE_JAVASCRIPT_BIN}/libSystem.Runtime.InteropServices.JavaScript.Native.js")
6053
set(JS_BROWSER_HOST
61-
"${CLR_ARTIFACTS_OBJ_DIR}/coreclr/browser.wasm.${CMAKE_BUILD_TYPE}/corehost/libBrowserHost.js")
54+
"${NATIVE_JAVASCRIPT_BIN}/libBrowserHost.js")
6255
set(JS_SYSTEM_NATIVE_BROWSER_EXPOST
6356
"${CMAKE_CURRENT_SOURCE_DIR}/../../libs/System.Native.Browser/libSystem.Native.Browser.extpost.js")
6457

@@ -67,6 +60,11 @@ set_target_properties(browserhost PROPERTIES
6760
LINK_FLAGS "--js-library ${JS_SYSTEM_NATIVE_BROWSER} --js-library ${JS_SYSTEM_BROWSER_UTILS} --js-library ${JS_SYSTEM_RUNTIME_INTEROPSERVICES_JAVASCRIPT_NATIVE} --js-library ${JS_BROWSER_HOST} --extern-post-js ${JS_SYSTEM_NATIVE_BROWSER_EXPOST}"
6861
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
6962

63+
target_compile_options(browserhost PRIVATE
64+
-fwasm-exceptions
65+
-msimd128
66+
)
67+
7068
if (UPPERCASE_CMAKE_BUILD_TYPE STREQUAL DEBUG)
7169
target_link_options(browserhost PRIVATE
7270
# -sVERBOSE
@@ -98,16 +96,19 @@ target_link_options(browserhost PRIVATE
9896
-Wno-unused-command-line-argument
9997
-Wl,-error-limit=0)
10098

101-
target_link_libraries(
102-
browserhost
103-
PRIVATE
104-
hostmisc
105-
clrinterpreter
99+
target_link_libraries(browserhost PUBLIC
100+
BrowserHost-Static
101+
)
102+
target_link_libraries(browserhost PRIVATE
106103
${NATIVE_LIBS}
107-
108-
${START_WHOLE_ARCHIVE}
109-
${RUNTIMEINFO_LIB}
110-
${END_WHOLE_ARCHIVE}
111104
)
112105

106+
install(TARGETS browserhost DESTINATION corehost COMPONENT runtime)
107+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/dotnet.native.wasm DESTINATION corehost COMPONENT runtime)
108+
109+
# this is for liveBuilds.targets
110+
install(TARGETS browserhost DESTINATION ${STATIC_LIB_DESTINATION})
111+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/dotnet.native.wasm DESTINATION ${STATIC_LIB_DESTINATION})
112+
install(FILES ${CLR_SRC_NATIVE_DIR}/package.json DESTINATION ${STATIC_LIB_DESTINATION})
113+
113114
add_subdirectory(sample)

src/native/corehost/browserhost/ReadMe.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ It's **JavaScript ES6 module**
1616
Implements native part of the CoreCLR host and exposes it as an internal JavaScript interface to the loader.
1717
It is **Emscripten application** statically linked from libraries.
1818

19-
- `host/index.ts` -> compiled -> `libBrowserHost.js` linked -> `dotnet.native.js`
20-
- `libBrowserHost.footer.js` -> compiled -> `libBrowserHost.js` linked -> `dotnet.native.js`
2119
- `libSystem.Native.Browser.js` linked -> `dotnet.native.js`
2220
- `libSystem.Browser.Utils.js` linked -> `dotnet.native.js`
2321
- `libSystem.Runtime.InteropServices.JavaScript.Native.js` linked -> `dotnet.native.js`
24-
- `browserhost.cpp` compiled + linked -> `dotnet.native.wasm`
2522
- `libSystem.Native.Browser.a` linked -> `dotnet.native.wasm`
2623
- `libSystem.Runtime.InteropServices.JavaScript.Native.a` linked -> `dotnet.native.wasm`
24+
- `host/index.ts` -> compiled -> `libBrowserHost.js` linked -> `dotnet.native.js`
25+
- `host/libBrowserHost.footer.js` -> compiled -> `libBrowserHost.js` linked -> `dotnet.native.js`
26+
- `host/browserhost.cpp` compiled -> `libBrowserHost.a` linked -> `dotnet.native.wasm`
27+
- `empty.c` compiled + linked -> `dotnet.native.wasm`
2728

2829
## Build
2930
TypeScript is compiled by `src/native/rollup.config.js`
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
#include "stdio.h"
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Licensed to the .NET Foundation under one or more agreements.
2+
# The .NET Foundation licenses this file to you under the MIT license.
3+
4+
project(BrowserHost-Static)
5+
set(DOTNET_PROJECT_NAME "BrowserHost-Static")
6+
7+
configure_file(${CLR_SRC_NATIVE_DIR}/corehost/configure.h.in ${GENERATED_INCLUDE_DIR}/corehost/configure.h)
8+
target_include_directories(hostmisc_interface INTERFACE ${GENERATED_INCLUDE_DIR}/corehost)
9+
10+
include(configure.cmake)
11+
12+
set(BROWSERHOST_STATIC_SOURCES
13+
./browserhost.cpp
14+
native.rc
15+
)
16+
17+
set(STATIC_LIB_DESTINATION
18+
${CLR_ARTIFACTS_BIN_DIR}/native/net${CMAKE_NET_CORE_APP_CURRENT_VERSION}-browser-${CMAKE_BUILD_TYPE}-wasm/)
19+
20+
add_compile_definitions(FEATURE_APPHOST)
21+
add_definitions(-DFEATURE_APPHOST=1)
22+
add_definitions(-DFEATURE_STATIC_HOST=1)
23+
24+
# WASM-TODO set(RUNTIMEINFO_LIB runtimeinfo)
25+
26+
add_library(BrowserHost-Static
27+
STATIC
28+
${BROWSERHOST_STATIC_SOURCES}
29+
)
30+
set_target_properties(BrowserHost-Static PROPERTIES OUTPUT_NAME BrowserHost CLEAN_DIRECT_OUTPUT 1)
31+
32+
# this would build libBrowserHost.js
33+
add_subdirectory(../../../libs/Common/JavaScript common-js)
34+
add_dependencies(BrowserHost-Static System.Native.Browser-Rollup)
35+
36+
target_compile_options(BrowserHost-Static PRIVATE
37+
-fwasm-exceptions
38+
-msimd128
39+
)
40+
target_link_libraries(BrowserHost-Static PRIVATE
41+
hostmisc
42+
43+
${START_WHOLE_ARCHIVE}
44+
${RUNTIMEINFO_LIB}
45+
${END_WHOLE_ARCHIVE}
46+
)
47+
48+
install(TARGETS BrowserHost-Static DESTINATION corehost COMPONENT runtime)
49+
install(TARGETS BrowserHost-Static DESTINATION ${STATIC_LIB_DESTINATION} COMPONENT libs)

0 commit comments

Comments
 (0)