julelang / jule

Effective programming language to build efficient, fast, reliable and safe software while maintaining simplicity
https://jule.dev
BSD 3-Clause "New" or "Revised" License
128 stars 13 forks source link

ci/cd: calling WriteConsoleW function on GitHub Actions fails #107

Open mertcandav opened 2 months ago

mertcandav commented 2 months ago

What would you like to share?

After correction solving of the issue #34, I created Windows GitHub Actions workflows to use.

The Jule API and Jule standard library uses the WriteConsoleW function of Windows for writing to console. The WriteConsoleW function usually used in Unicode cases, uses UTF-16 encoding. Jule uses UTF-8 encoded strings by default which is supports Unicode characters also, therefore calls WriteConsoleW function after UTF-8 to UTF-16 conversion.

This operation works fine on our local test systems; on 2 different AMD64 Windows 10 and single ARM64 Windows 11, works as expected. On GitHub Actions with windows-latest, the WriteConsoleW function returns zero which is means failed.

I created a new workflow with simple C++ program and tested with to understand whether this problem relevant with Jule implementation.

That's my simple C++ program to test;

#include <iostream>
#include <windows.h>

int main() {
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    wchar_t text[] = {104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 0};
    WriteConsoleW(hConsole, text, 11, nullptr, nullptr);
    return 0;
}

And that's my compile command: clang++ -O0 --std=c++17 -o main.exe main.cpp -lshell32 -lkernel32

The test program above, writes hello world to the stdout handle. The variable text stores UTF-16 encoded hello world characters with NULL termination. Works as expected on local machines unlike GitHub Actions. On GitHub Actions, will not prints anything and failed.

Additional information

GitHub Actions uses UTF-8 by default. Printing with std::cout or std::wcout with UTF-8 encoded strings works and displayed fine, but std::wcout output is not displayed well with UTF-16 encoded strings.

As far as I tested, GitHub Actions's "UTF-8 by default" approach is not a problem. I tested on local machines with UTF-8 localization and calling WriteConsoleW function with UTF-16 encoded strings works and displayed as expected.