Thread overview
LDC 1.40.0-beta3
Sep 09
kinke
Sep 09
kinke
Sep 09
ryuukk_
Sep 09
kinke
September 09

Glad to announce the 3rd beta for LDC 1.40. Major changes:

  • Based on D ~2.110.0 (yesterday's upstream stable).
  • LLVM for prebuilt packages bumped to v18.1.8 (incl. macOS arm64).
  • Android: NDK for prebuilt package bumped from r26d to r27.
  • Mainly for distro package maintainers: Use system zlib instead of Phobos' vendored version through CMake -DPHOBOS_SYSTEM_ZLIB=ON. Thanks Andrei!
  • Edge-case fixes regarding IR struct layouts and link-time culling (for ELF targets).

Full release log and downloads: https://github.com/ldc-developers/ldc/releases/tag/v1.40.0-beta3

Please help test, and thanks to all contributors & sponsors!

September 09

Oh, I forgot an item:

  • Emscripten: The compiler now mimicks a musl Linux platform wrt. extra predefined versions.

This should pave the way for supporting Emscripten in druntime & Phobos (via version(Emscripten) special cases), which is probably much simpler with the musl libc interface than the WASI interface directly.

September 09

On Monday, 9 September 2024 at 17:15:47 UTC, kinke wrote:

>

Oh, I forgot an item:

  • Emscripten: The compiler now mimicks a musl Linux platform wrt. extra predefined versions.

This should pave the way for supporting Emscripten in druntime & Phobos (via version(Emscripten) special cases), which is probably much simpler with the musl libc interface than the WASI interface directly.

Thanks! i got SDL + printf working

Follow what's bellow, then browse: http://0.0.0.0:8000/

The process could be simplified imo, but that's a promising start

$ ldc2 -mtriple=wasm32-emscripten-none -L-allow-undefined -relocation-model=pic app.d
$ mkdir dist/
$ emcc -v -O0 -s WASM=1 -s USE_SDL=2 -s USE_SDL_IMAGE=2 -s RELOCATABLE=1  -s ENVIRONMENT=web -o dist/index.html app.o
$ python -m http.server 8000 --directory dist/
import core.stdc.stdio;

__gshared:
SDL_Window* window = null;
SDL_Renderer* renderer = null;
SDL_Surface* screen_surface = null;
SDL_Event* event = null;

bool is_running = true;

extern (C) void main()
{
    printf("hello from D\n");
    init_game();
}

extern (C) void mainloop()
{
    if (!is_running)
    {
        emscripten_cancel_main_loop();
        return;
    }
    SDL_FillRect(screen_surface, null, 0xFF0000);
    SDL_UpdateWindowSurface(window);

}

extern (C) void _start() {} // should not be needed


extern (C) void init_game()
{
    if (SDL_Init(SDL_INIT_VIDEO) < 0)
    {
        fprintf(stderr, "could not initialize sdl2: %s\n", SDL_GetError());
        emscripten_cancel_main_loop();
        return;
    }
    window = SDL_CreateWindow("hello_sdl2", SDL_WINDOWPOS_UNDEFINED,
            SDL_WINDOWPOS_UNDEFINED, 800, 600, SDL_WINDOW_SHOWN);
    if (window == null)
    {
        fprintf(stderr, "could not create window: %s\n", SDL_GetError());
        emscripten_cancel_main_loop();
        return;
    }
    screen_surface = SDL_GetWindowSurface(window);

    emscripten_set_main_loop(&mainloop, 0, 1);
}

extern (C)
{

    // emscripten API
    alias em_callback_func = void function();
    void emscripten_set_main_loop(em_callback_func, int, int);
    void emscripten_cancel_main_loop();

    // SDL

    struct SDL_Rect
    {
        int x, y;
        int w, h;
    }

    alias SDL_Window = void;
    alias SDL_Renderer = void;
    alias SDL_Event = void;
    alias SDL_Surface = void;

    enum SDL_INIT_TIMER = 0x00000001u;
    enum SDL_INIT_AUDIO = 0x00000010u;
    enum SDL_INIT_VIDEO = 0x00000020u;
    enum SDL_INIT_JOYSTICK = 0x00000200u;
    enum SDL_INIT_HAPTIC = 0x00001000u;
    enum SDL_INIT_GAMEPAD = 0x00002000u;
    enum SDL_INIT_EVENTS = 0x00004000u;
    enum SDL_INIT_SENSOR = 0x00008000u;
    enum SDL_INIT_CAMERA = 0x00010000u;
    int SDL_Init(uint);

    enum SDL_WINDOWPOS_UNDEFINED_MASK = 0x1FFF0000u;
    enum SDL_WINDOWPOS_UNDEFINED = SDL_WINDOWPOS_UNDEFINED_MASK | 0;
    enum SDL_WINDOW_SHOWN = 0x00000004;
    SDL_Window* SDL_CreateWindow(const char* title, int x, int y, int w, int h, uint flags);

    SDL_Surface* SDL_GetWindowSurface(SDL_Window*);

    int SDL_UpdateWindowSurface(SDL_Window*);

    int SDL_FillRect(SDL_Surface*, const(SDL_Rect)* rect, uint color);

    const(char)* SDL_GetError();
}
September 09

On Monday, 9 September 2024 at 17:53:34 UTC, ryuukk_ wrote:

>

Thanks! i got SDL + printf working

Cool, thanks for the idea in the 1st place (I thought Emscripten was some legacy framework compiling to JavaScript... ;)) and providing all required info via a minimal example. :+1: