Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions .github/workflows/build-apphost.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ jobs:

- name: linux_x64
os: ubuntu-latest
toolchain: stable-x86_64-unknown-linux-gnu
toolchain: 1.86.0-x86_64-unknown-linux-gnu
target: x86_64-unknown-linux-gnu
container: quay.io/pypa/manylinux_2_28_x86_64 #https://kobzol.github.io/rust/ci/2021/05/07/building-rust-binaries-in-ci-that-work-with-older-glibc.html

- name: macos_x64
os: macos-13
toolchain: stable-x86_64-apple-darwin
toolchain: 1.86.0-x86_64-apple-darwin
target: x86_64-apple-darwin

- name: macos_arm64
os: macos-latest
toolchain: stable-x86_64-apple-darwin
toolchain: 1.86.0-x86_64-apple-darwin
target: aarch64-apple-darwin

ui:
Expand Down Expand Up @@ -98,4 +98,4 @@ jobs:
with:
name: apphost-${{ matrix.target.name }}-${{ matrix.ui }}
path: piton-${{ matrix.target.name }}-${{ matrix.ui }}${{ matrix.target.exec_suffix }}
if-no-files-found: error
if-no-files-found: error
1 change: 1 addition & 0 deletions apphost/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion apphost/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ static_vcruntime = "2.0"
[target.'cfg(target_os = "linux")'.dependencies]
gtk = { version = "0.18.1", optional = true }

[target.'cfg(unix)'.dependencies]
libc = { version = "0.2.172" }

[target.'cfg(target_os = "windows")'.dependencies]
windows = { version = "0.51.1", features = ["Win32_Foundation", "Win32_UI_WindowsAndMessaging", "Win32_UI_Controls", "Win32_System_Console", "Win32_System_LibraryLoader", "Win32_System_SystemServices", "Win32_Graphics_Gdi"], optional = true }

[target.'cfg(target_os = "macos")'.dependencies]
objc = { version = "0.2.7", optional = true }
cacao = { version = "0.4.0-beta2", optional = true }
cacao = { version = "0.4.0-beta2", optional = true }
13 changes: 12 additions & 1 deletion apphost/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use embed_manifest::{embed_manifest, new_manifest};
use std::process::{Command};

fn main() {
if std::env::var_os("CARGO_CFG_WINDOWS").is_some() {
Expand All @@ -9,5 +10,15 @@ fn main() {
embed_manifest(new_manifest("Piton")).expect("unable to embed manifest file");
}


if std::env::var_os("CARGO_FEATURE_TESTAPP").is_some() {
println!("cargo:rerun-if-changed=test");
Command::new("dotnet")

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Not sure if this places the output DLL in the right place (I would expect it to be somewhere in a bin/ directory); additionally, those output bin / obj dirs should probably be .gitignored.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The csproj contains <OutputPath>.</OutputPath> as well as <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> to make sure Test.dll lands in the correct folder, paths in the csproj are relative to that file. Consequently no bin directory is generated.

Added all other dotnet artifacts to .gitignore though.

.arg("build")
.arg("test/Test.csproj")
.status()
.expect("Failed to build test C#");
}

println!("cargo:rerun-if-changed=build.rs")
}
}
28 changes: 27 additions & 1 deletion apphost/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ pub fn launch_app_binary(runtime_dir: Option<&Path>, app_info: &AppInfo) -> Resu
let args: Vec<PdCString> = env::args_os().map(PdCString::from_os_str).collect::<Result<_, _>>()?;
let app_path = PdCString::from_os_str(app_info.app_path.as_os_str())?;

//Apply required fixes
#[cfg(unix)]
unix::fixup_signal_handling();

let res = unsafe {
let args = args.iter().map(|s| s.as_ptr()).collect::<Vec<_>>();

Expand All @@ -163,4 +167,26 @@ pub fn launch_app_binary(runtime_dir: Option<&Path>, app_info: &AppInfo) -> Resu
Ok(err) => Err(Box::new(err)),
Err(_) => Ok(res)
}
}
}

#[cfg(unix)]
mod unix {

@Popax21 Popax21 May 24, 2025

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This module could use a cargo fmt invocation .-.
To be precise, this mainly affects the line wrapping (present inside the function, but not outside it), and the inconsistent spacing around the use directives.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Applied all changes that cargo fmt did for that section of the code.

use libc::{sigaction, sigaltstack, stack_t, SIGSEGV, SIG_DFL, SS_DISABLE};
use std::{mem, ptr};

//On Unix it is required for us to manually remove the registered signal handler altstack in order to have a stable runtime.
//This is due to rust registering a tiny altstack and then the runtime rolling with it, which causes it to overflow it when allocating a large structure.
//See https://github.com/dotnet/runtime/issues/115438 for more details.
pub fn fixup_signal_handling() {
//Removing the SIGSEGV handler is not strictly required, but since we are messing with the altstack we also reset it to the default, for safety

let mut action: sigaction = unsafe { mem::zeroed() };
action.sa_sigaction = SIG_DFL;
unsafe { sigaction(SIGSEGV, &action, ptr::null_mut()) };

let mut altstack: stack_t = unsafe { mem::zeroed() };
altstack.ss_flags = SS_DISABLE;
unsafe { sigaltstack(&altstack, ptr::null_mut()) };
}
}

7 changes: 6 additions & 1 deletion apphost/test/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
piton-runtime
piton-runtime
*.deps.json
*.dll
*.pdb
*.runtimeconfig.json
obj/
14 changes: 14 additions & 0 deletions apphost/test/Test.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Console.WriteLine("Hello, World!");
#pragma warning disable CS8600 // Intentional NRE for testing purposes
#pragma warning disable CS8602 // See above
// Test if NREs work properly since by default rust uses a signal handler altstack which can
// be too small for the runtime to work with, see https://github.com/dotnet/runtime/issues/115438
// for the full details

// Piton currently includes a hacky fix to work around that

try {
((object)null).GetType();
} catch (NullReferenceException) {
Console.WriteLine("NRE caught!");
}
15 changes: 15 additions & 0 deletions apphost/test/Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
</PropertyGroup>

<PropertyGroup>
<UseAppHost>false</UseAppHost>
<OutputPath>.</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>
</Project>
23 changes: 0 additions & 23 deletions apphost/test/Test.deps.json

This file was deleted.

Binary file removed apphost/test/Test.dll
Binary file not shown.
9 changes: 0 additions & 9 deletions apphost/test/Test.runtimeconfig.json

This file was deleted.

29 changes: 15 additions & 14 deletions apphost/test/piton-runtime.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
# Latest LTS as of April 19th 2025
windows-x86:
version: 7.0.12
download: https://download.visualstudio.microsoft.com/download/pr/e6be672b-53a9-4050-9b55-53f74a55523c/b59ab5af9be85681cf415865a159624f/dotnet-runtime-7.0.12-win-x86.zip
download-sha512: 760f4483b9848c2165be30ad4623de4099529fdcbf61c4e6c1738dfe22e3d776ca7ced89e4d7485dc0337c988b1c3bf1c5757a01e97d156df4ad0cf848226244
version: 8.0.15
download: https://builds.dotnet.microsoft.com/dotnet/Runtime/8.0.15/dotnet-runtime-8.0.15-win-x86.zip
download-sha512: b9980345c84443381b92d8d3c56a90244ec90e6f7edfbf09dd665b29a807705592606997e7e85bb7f6357f49feb5aa41506ec1426a4208352a326736bda6c441
download-format: zip

windows-x86_64:
version: 7.0.12
download: https://download.visualstudio.microsoft.com/download/pr/6d97a102-c4f3-4183-91d7-d810e96e73a1/272349ea2adf0145d9364e2c12bd23a4/dotnet-runtime-7.0.12-win-x64.zip
download-sha512: fada96dfe5c0ff99799032b21323b0c75764df8c7991e67c0f2757a0f4d9946c68dee07831a0bda7e884713749150121d618973d14bdcc915d389799b36848bb
version: 8.0.15
download: https://builds.dotnet.microsoft.com/dotnet/Runtime/8.0.15/dotnet-runtime-8.0.15-win-x64.zip
download-sha512: 1d486895ecc1c99586a8dd221a1a21c507ce42eaf4262345f93f0a2cae7e23733360b742f2d5b803c56a1199cb00ca20a5ee5c911d63118e1930e07068a7cccb
download-format: zip

linux-x86_64:
version: 7.0.12
download: https://download.visualstudio.microsoft.com/download/pr/47a663ab-0c5f-4502-9ea1-93c27df8f9ed/5ee65ca13eb40220631dab82a27972d8/dotnet-runtime-7.0.12-linux-x64.tar.gz
download-sha512: 74bea25e88bd917a733a6899a3b3c9ac40c85a64f82dc0f36840714669621716afbb8fec6c3c398b1ffb522c0ed11958862cff5a4be0bf6268188cdb276bc109
version: 8.0.15
download: https://builds.dotnet.microsoft.com/dotnet/Runtime/8.0.15/dotnet-runtime-8.0.15-linux-x64.tar.gz
download-sha512: 833a848541ba6f71c8792168914856e16de6f71cf0a481c5990f3622b0e3f83123e6024bcabf6b955a7c92e8e904181d40d3bd612595a0d8c47a421267a91ca6
download-format: targz

macos-x86_64:
version: 7.0.12
download: https://download.visualstudio.microsoft.com/download/pr/5a3eed2a-4c5f-4c05-9ef5-4b59de889a9e/4a577fd9e4b278dfebc16d901691b90f/dotnet-runtime-7.0.12-osx-x64.tar.gz
download-sha512: 3cfa807b64eb345ff104f33d7120d7d973443d40aedfe5fb49c0b67adb69f743c18a6e762a8463f59ee29b4a291970e8af48f97f841a94ed220809b56258b0e0
download-format: targz
version: 8.0.15
download: https://builds.dotnet.microsoft.com/dotnet/Runtime/8.0.15/dotnet-runtime-8.0.15-osx-x64.tar.gz
download-sha512: e488b4dca3cb08a144b50d4428e4185b7a8cf7486886acfee8fc00c1145bd82d7bc7e66acea76a575869f16578babc6708fe1045839deca6ca848188ca59a51c
download-format: targz