Skip to content

Commit

Permalink
Switch from loading timezonedata from runtime-assets to including dot…
Browse files Browse the repository at this point in the history
…net.timezones.blat in runtime pack

Remove edits to WasmSample makefile
Remove package references to System.Runtime.TestData
  • Loading branch information
tqiu8 committed Jun 29, 2020
1 parent 619a90e commit ac91ed2
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 45 deletions.
4 changes: 0 additions & 4 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@
<Uri>https://github.com/dotnet/runtime-assets</Uri>
<Sha>629993236116221fba87fe1de6d7893dd02c3722</Sha>
</Dependency>
<Dependency Name="System.Runtime.TestData" Version="5.0.0-beta.20319.2">
<Uri>https://github.com/dotnet/runtime-assets</Uri>
<Sha>629993236116221fba87fe1de6d7893dd02c3722</Sha>
</Dependency>
<Dependency Name="System.Private.Runtime.UnicodeData" Version="5.0.0-beta.20319.2">
<Uri>https://github.com/dotnet/runtime-assets</Uri>
<Sha>629993236116221fba87fe1de6d7893dd02c3722</Sha>
Expand Down
3 changes: 2 additions & 1 deletion eng/liveBuilds.targets
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@
<LibrariesRuntimeFiles Condition="'$(TargetOS)' == 'Browser'"
Include="
$(LibrariesNativeArtifactsPath)dotnet.js;
$(LibrariesNativeArtifactsPath)dotnet.wasm;"
$(LibrariesNativeArtifactsPath)dotnet.wasm;
$(LibrariesNativeArtifactsPath)dotnet.timezones.blat;"
IsNative="true" />
</ItemGroup>

Expand Down
3 changes: 2 additions & 1 deletion eng/testing/WasmRunnerTemplate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ XHARNESS_OUT="$EXECUTION_DIR/xharness-output"
dotnet xharness wasm test --engine=$JAVASCRIPT_ENGINE \
--js-file=runtime.js -v \
--output-directory=$XHARNESS_OUT \
-- --enable-gc --run WasmTestRunner.dll ${@:2}
-- --enable-gc --enable-zoneinfo \
--run WasmTestRunner.dll ${@:2}

_exitCode=$?

Expand Down
1 change: 1 addition & 0 deletions src/libraries/Native/native-binplace.proj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<BinPlaceItem Include="$(NativeBinDir)*.dwarf" />
<BinPlaceItem Condition="'$(TargetOS)' == 'Browser'" Include="$(NativeBinDir)dotnet.js" />
<BinPlaceItem Condition="'$(TargetOS)' == 'Browser'" Include="$(NativeBinDir)dotnet.wasm" />
<BinPlaceItem Condition="'$(TargetOS)' == 'Browser'" Include="$(NativeBinDir)dotnet.timezones.blat" />
<FileWrites Include="@(BinPlaceItem)" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,6 @@
<Compile Include="$(CommonTestPath)System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs"
Link="Common\System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Runtime.TestData" Version="$(SystemRuntimeTestDataVersion)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="TestLoadAssembly\TestLoadAssembly.csproj" />
<ProjectReference Include="TestCollectibleAssembly\TestCollectibleAssembly.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion src/mono/netcore/sample/wasm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ clean:
rm -rf bin

run:
cd bin/$(CONFIG)/publish && ~/.jsvu/v8 --expose_wasm runtime.js -- --enable-gc --enable-zoneinfo --run WasmSample.dll
cd bin/$(CONFIG)/publish && ~/.jsvu/v8 --expose_wasm runtime.js -- --enable-gc --run WasmSample.dll

runtimepack:
EMSDK_PATH=$(abspath $(TOP)/src/mono/wasm/emsdk) $(TOP)/build.sh -c $(CONFIG) -os Browser -arch wasm -subset Mono+Libs
2 changes: 1 addition & 1 deletion src/mono/wasm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ MONO_LIBS = \
$(MONO_BIN_DIR)/libmono-icall-table.a \
${SYS_NATIVE_DIR}/libSystem.Native.a

EMCC_FLAGS=--profiling-funcs -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN=1 -s ALIASING_FUNCTION_POINTERS=0 -s NO_EXIT_RUNTIME=1 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall', 'FS_createPath', 'FS_createDataFile', 'cwrap', 'setValue', 'getValue', 'UTF8ToString', 'addFunction']" -s "EXPORTED_FUNCTIONS=['_putchar']" --source-map-base http://example.com -s WASM_OBJECT_FILES=0 -s FORCE_FILESYSTEM=1 -s USE_ZLIB=1
EMCC_FLAGS=--profiling-funcs -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN=1 -s ALIASING_FUNCTION_POINTERS=0 -s NO_EXIT_RUNTIME=1 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall', 'FS_createPath', 'FS_createDataFile', 'cwrap', 'setValue', 'getValue', 'UTF8ToString', 'addFunction']" -s "EXPORTED_FUNCTIONS=['_putchar']" --source-map-base http://example.com -emit-llvm -s FORCE_FILESYSTEM=1 -s USE_ZLIB=1
EMCC_DEBUG_FLAGS =-g -Os -s ASSERTIONS=1 -DENABLE_NETCORE=1 -DDEBUG=1
EMCC_RELEASE_FLAGS=-Oz --llvm-opts 2 --llvm-lto 1 -DENABLE_NETCORE=1

Expand Down
34 changes: 2 additions & 32 deletions src/mono/wasm/runtime-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,39 +206,9 @@ var Module = {
f ();
}
if (enable_zoneinfo) {
FS.mkdir("usr");
Module['FS_createPath']('/', 'usr', true, true);
FS.mkdir("share");
Module['FS_createPath']('/usr', 'share', true, true);
FS.mkdir("/usr/share/zoneinfo")
Module['FS_createPath']('/usr/share/zoneinfo', 'Indian', true, true);
Module['FS_createPath']('/usr/share/zoneinfo', 'Atlantic', true, true);
Module['FS_createPath']('/usr/share/zoneinfo', 'US', true, true);
Module['FS_createPath']('/usr/share/zoneinfo', 'Brazil', true, true);
Module['FS_createPath']('/usr/share/zoneinfo', 'Pacific', true, true);
Module['FS_createPath']('/usr/share/zoneinfo', 'Arctic', true, true);
Module['FS_createPath']('/usr/share/zoneinfo', 'America', true, true);
Module['FS_createPath']('/usr/share/zoneinfo/America', 'Indiana', true, true);
Module['FS_createPath']('/usr/share/zoneinfo/America', 'Argentina', true, true);
Module['FS_createPath']('/usr/share/zoneinfo/America', 'Kentucky', true, true);
Module['FS_createPath']('/usr/share/zoneinfo/America', 'North_Dakota', true, true);
Module['FS_createPath']('/usr/share/zoneinfo', 'Australia', true, true);
Module['FS_createPath']('/usr/share/zoneinfo', 'Etc', true, true);
Module['FS_createPath']('/usr/share/zoneinfo', 'Asia', true, true);
Module['FS_createPath']('/usr/share/zoneinfo', 'Antarctica', true, true);
Module['FS_createPath']('/usr/share/zoneinfo', 'Europe', true, true);
Module['FS_createPath']('/usr/share/zoneinfo', 'Mexico', true, true);
Module['FS_createPath']('/usr/share/zoneinfo', 'Africa', true, true);
Module['FS_createPath']('/usr/share/zoneinfo', 'Chile', true, true);
Module['FS_createPath']('/usr/share/zoneinfo', 'Canada', true, true);
var zoneInfoData = new Uint8Array(read ('supportFiles/zoneinfo/zoneinfo.data', 'binary'));
var metadata = JSON.parse(read ("supportFiles/zoneinfo/mono-webassembly-zoneinfo-fs-smd.js.metadata", 'utf-8'));
var files = metadata.files;
for (var i = 0; i < files.length; ++i) {
var byteArray = zoneInfoData.subarray(files[i].start, files[i].end);
writeContentToFile(byteArray, `/usr/share${files[i].filename}`);
}
MONO.wasm_load_timezone_data ("dotnet.timezones.blat");
}

MONO.mono_load_runtime_and_bcl (
config.vfs_prefix,
config.deploy_prefix,
Expand Down
Binary file added src/mono/wasm/runtime/dotnet.timezones.blat
Binary file not shown.
60 changes: 59 additions & 1 deletion src/mono/wasm/runtime/library_mono.js
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,64 @@ var MonoSupportLib = {
// and nested class names like Foo/Bar to Foo.Bar
return className.replace(/\//g, '.').replace(/`\d+/g, '');
},

wasm_load_timezone_data: function (file_name) {
var binary = read(file_name, "binary");
// The timezone file is generated by https://github.com/dotnet/blazor/tree/master/src/TimeZoneData.
// The file format of the TZ file look like so
//
// [4-byte magic number]
// [4 - byte length of manifest]
// [json manifest]
// [data bytes]
//
// The json manifest is an array that looks like so:
//
// [...["America/Fort_Nelson",2249],["America/Glace_Bay",2206]..]
//
// where the first token in each array is the relative path of the file on disk, and the second is the
// length of the file. The starting offset of a file can be calculated using the lengths of all files
// that appear prior to it.
var remainingData = new Uint8Array (binary);
var dataview = new DataView(remainingData.buffer);
var magic = dataview.getUint32(0, true);
// get magic number
if (magic != 0x626c6174) {
throw new Error ("File is of wrong type");
}
var manifestSize = dataview.getUint32(4, true);
var manifestContent = Module.UTF8ArrayToString(remainingData, 8, manifestSize);
var manifest = JSON.parse(manifestContent.split(/[a-zA-Z//_]+, [0-9]+/g));
remainingData = remainingData.slice(manifestSize+8);

// Create the folder structure
// /usr/share/zoneinfo
// /usr/share/zoneinfo/Africa
// /usr/share/zoneinfo/Asia
// ..
FS.mkdir("usr");
Module['FS_createPath']('/', 'usr', true, true);
FS.mkdir("share");
Module['FS_createPath']('/usr', 'share', true, true);
FS.mkdir("/usr/share/zoneinfo");
var folders = new Set()
manifest.filter(m => {
m = m[0].split('/')
if (m.length === 3) folders.add(m.slice(0,2).join('/'));
folders.add(m[0]);
});
folders.forEach(folder => {
Module['FS_createPath']('/usr/share/zoneinfo', folder, true, true);
});

for (row of manifest) {
var name = row[0];
var length = row[1];
var bytes = remainingData.slice(0, length);
Module['FS_createDataFile'](`/usr/share/zoneinfo/${name}`, null, bytes, true, true);
remainingData = remainingData.slice(length);
}
}
},

mono_wasm_add_typed_value: function (type, str_value, value) {
Expand Down Expand Up @@ -993,7 +1051,7 @@ var MonoSupportLib = {
mono_wasm_fire_bp: function () {
console.log ("mono_wasm_fire_bp");
debugger;
}
},
};

autoAddDeps(MonoSupportLib, '$MONO')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public override bool Execute ()
Directory.CreateDirectory(Path.Join(AppDir, "managed"));
foreach (var assembly in _assemblies!.Values)
File.Copy(assembly.Location, Path.Join(AppDir, "managed", Path.GetFileName(assembly.Location)), true);
foreach (var f in new string[] { "dotnet.wasm", "dotnet.js" })
foreach (var f in new string[] { "dotnet.wasm", "dotnet.js", "dotnet.timezones.blat" })
File.Copy(Path.Join (MicrosoftNetCoreAppRuntimePackDir, "native", f), Path.Join(AppDir, f), true);
File.Copy(MainJS!, Path.Join(AppDir, "runtime.js"), true);

Expand Down

0 comments on commit ac91ed2

Please sign in to comment.