Skip to content

Commit

Permalink
Use Clang for Windows (m68) (#1007)
Browse files Browse the repository at this point in the history
* Switch to Clang for Win32
* Make sure to first dispose the native instance  
  In some cases, the native instance has callbacks into the managed world. This can be seen with the documents, they have a flush callback which requires that the managed objects all still exist. This is a valid situation where some object owns other managed objects. It is invalid to have some child object reference the parent object as there is no way of informing the child that it has no parent.
  • Loading branch information
mattleibow authored Nov 11, 2019
1 parent 29d87a1 commit 9da3dad
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 5 deletions.
7 changes: 3 additions & 4 deletions binding/Binding/SKObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,12 @@ protected virtual void Dispose (bool disposing)
if (Interlocked.CompareExchange (ref isDisposed, 1, 0) != 0)
return;

if (disposing) {
DisposeManaged ();
}

if (Handle != IntPtr.Zero && OwnsHandle)
DisposeNative ();

if (disposing)
DisposeManaged ();

Handle = IntPtr.Zero;
}

Expand Down
4 changes: 3 additions & 1 deletion build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ DirectoryPath NUGET_PACKAGES = EnvironmentVariable ("NUGET_PACKAGES") ?? PROFILE
DirectoryPath ANDROID_SDK_ROOT = EnvironmentVariable ("ANDROID_SDK_ROOT") ?? EnvironmentVariable ("ANDROID_HOME") ?? PROFILE_PATH.Combine ("android-sdk");
DirectoryPath ANDROID_NDK_HOME = EnvironmentVariable ("ANDROID_NDK_HOME") ?? EnvironmentVariable ("ANDROID_NDK_ROOT") ?? PROFILE_PATH.Combine ("android-ndk");
DirectoryPath TIZEN_STUDIO_HOME = EnvironmentVariable ("TIZEN_STUDIO_HOME") ?? PROFILE_PATH.Combine ("tizen-studio");
DirectoryPath LLVM_HOME = EnvironmentVariable ("LLVM_HOME") ?? "C:/Program Files/LLVM";

DirectoryPath ROOT_PATH = MakeAbsolute(Directory("."));
DirectoryPath DEPOT_PATH = MakeAbsolute(ROOT_PATH.Combine("externals/depot_tools"));
Expand Down Expand Up @@ -572,6 +573,7 @@ Information ("SDK Paths:");
Information (" Android SDK: {0}", ANDROID_SDK_ROOT);
Information (" Android NDK: {0}", ANDROID_NDK_HOME);
Information (" Tizen Studio: {0}", TIZEN_STUDIO_HOME);
Information (" LLVM/Clang: {0}", LLVM_HOME);
Information ("");

Information ("Environment Variables (whitelisted):");
Expand All @@ -582,7 +584,7 @@ var envVarsWhitelist = new [] {
"node_label", "build_id", "git_sha", "git_branch_name",
"feature_name", "msbuild_exe", "python_exe", "preview_label",
"home", "userprofile", "nuget_packages", "build_arch",
"android_sdk_root", "android_ndk_root",
"android_sdk_root", "android_ndk_root", "llvm_home",
"android_home", "android_ndk_home", "tizen_studio_home"
};
var envVars = EnvironmentVariables ();
Expand Down
3 changes: 3 additions & 0 deletions cake/BuildExternals.cake
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,13 @@ Task ("externals-windows")
return;
}

var clang = string.IsNullOrEmpty(LLVM_HOME.FullPath) ? "" : $"clang_win='{LLVM_HOME}' ";

// generate native skia build files
GnNinja ($"win/{arch}", "SkiaSharp",
$"is_official_build=true skia_enable_tools=false " +
$"target_os='win' target_cpu='{skiaArch}' " +
clang +
$"skia_use_icu=false skia_use_sfntly=false skia_use_piex=true skia_use_dng_sdk=true " +
$"skia_use_system_expat=false skia_use_system_libjpeg_turbo=false skia_use_system_libpng=false skia_use_system_libwebp=false skia_use_system_zlib=false " +
$"extra_cflags=[ '-DSKIA_C_DLL', '/MT', '/EHsc', '/Z7' ] " +
Expand Down
5 changes: 5 additions & 0 deletions scripts/azure-templates-bootstrapper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ jobs:
- ${{ if contains(parameters.name, '_android_') }}:
- pwsh: .\scripts\install-android-ndk.ps1
displayName: Install the Android NDK
# install llvm
- ${{ if endsWith(parameters.name, '_windows') }}:
- pwsh: .\scripts\install-llvm.ps1
displayName: Install LLVM
# install extra bits for the manged builds
- ${{ if not(startsWith(parameters.name, 'native_')) }}:
- task: UseDotNet@2
Expand Down Expand Up @@ -106,6 +110,7 @@ jobs:
- pwsh: .\scripts\retry-command.ps1 -RetryCount ${{ parameters.retryCount }} { .\bootstrapper.ps1 -t ${{ parameters.target }} -v ${{ parameters.verbosity }} -c ${{ coalesce(parameters.configuration, 'Release') }} ${{ parameters.additionalArgs }} }
env:
JavaSdkDirectory: $(JAVA_HOME)
LLVM_HOME: $(LLVM_HOME)
displayName: Run the bootstrapper for ${{ parameters.target }}
- ${{ if not(endsWith(parameters.name, '_windows')) }}:
- bash: ./scripts/retry-command.sh ${{ parameters.retryCount }} ./bootstrapper.sh -t ${{ parameters.target }} -v ${{ parameters.verbosity }} -c ${{ coalesce(parameters.configuration, 'Release') }} ${{ parameters.additionalArgs }}
Expand Down
24 changes: 24 additions & 0 deletions scripts/install-llvm.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Param(
[string] $Version = "9.0.0"
)

$ErrorActionPreference = 'Stop'

$url = "http://releases.llvm.org/${Version}/LLVM-${Version}-win64.exe"

$llvmTemp = "$HOME/llvm-temp"
$install = "$llvmTemp/llvm.exe"

# download
Write-Host "Downloading LLVM..."
New-Item -ItemType Directory -Force -Path "$llvmTemp" | Out-Null
(New-Object System.Net.WebClient).DownloadFile("$url", "$install")

# install
Write-Host "Installing LLVM..."
& $install /S

# make sure that LLVM is in LLVM_HOME
Write-Host "##vso[task.setvariable variable=LLVM_HOME;]C:\Program Files\LLVM";

exit $LASTEXITCODE
2 changes: 2 additions & 0 deletions tests/SkiaSharp.Desktop.Tests/SkiaSharp.Desktop.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@
</ItemGroup>
<ItemGroup>
<Content Include="..\..\output\native\windows\$(Platform)\libSkiaSharp.dll" CopyToOutputDirectory="Always" Condition=" '$(IsWindows)' == 'true' " />
<Content Include="..\..\output\native\windows\$(Platform)\libSkiaSharp.pdb" CopyToOutputDirectory="Always" Condition=" '$(IsWindows)' == 'true' " />
<Content Include="..\..\output\native\windows\$(Platform)\libHarfBuzzSharp.dll" CopyToOutputDirectory="Always" Condition=" '$(IsWindows)' == 'true' " />
<Content Include="..\..\output\native\windows\$(Platform)\libHarfBuzzSharp.pdb" CopyToOutputDirectory="Always" Condition=" '$(IsWindows)' == 'true' " />
<Content Include="..\..\output\native\osx\libSkiaSharp.dylib" CopyToOutputDirectory="Always" Condition=" '$(IsMacOS)' == 'true' " />
<Content Include="..\..\output\native\osx\libHarfBuzzSharp.dylib" CopyToOutputDirectory="Always" Condition=" '$(IsMacOS)' == 'true' " />
<Content Include="..\..\output\native\linux\$(Platform)\libSkiaSharp.so" CopyToOutputDirectory="Always" Condition=" '$(IsLinux)' == 'true' " />
Expand Down

0 comments on commit 9da3dad

Please sign in to comment.