call_end

    • Pl chevron_right

      Christian Hergert: Getting Started with Foundry

      news.movim.eu / PlanetGnome • 21 September • 2 minutes

    In addition to all the Libdex 1.0 fanfare, Foundry has also reached 1.0 for GNOME 49. That doesn’t mean it’s complete, but it does mean that what is there I feel pretty confident about from an API/ABI standpoint.

    If you have a project that works in GNOME Builder, it is a good time to test it out with Foundry! To get started you need to “initialize” a Foundry project similar to what you do with Git. This creates a minimal skeleton structure that Foundry will use for the project.

    cd myapp/
    foundry init

    At this point, you should have a .foundry/ directory in your project. Foundry will try to store everything it knows about your project in there. That includes settings, builds, cache, and tmp files. It also sets up a .gitignore file so that only the things you’re interested end up getting committed to the project’s git repository.

    Now we can build the project.

    foundry build

    Foundry will do all the same sort of SDK setup, cross-container build pipelines, and build system management that GNOME Builder does.

    To run the project, just run the following. It will handle building first if necessary too.

    foundry run

    If using a Flatpak manifest as your build configuration (you can check with foundry config list ) then it will handle all the same sort of details that Builder does.

    Building with Libfoundry

    Of course the command line tool is great for when you are needing to quickly do something in a terminal. But perhaps you want to integrate Foundry features into your own application or tools? Everything in the command line tool is available via libfoundry .

    To open an existing project with libfoundry, using just a directory to start, we can discover the `.foundry` directory location.

    g_autofree char *state_dir = NULL;
    DexFuture *future;
    
    future = foundry_context_discover (g_get_current_dir (), NULL);
    state_dir = dex_await_string (future, &error);

    We can use that information to load the project.

    g_autoptr(FoundryContext) context = NULL;
    DexFuture *future;
    
    future = foundry_context_new (state_dir, NULL, 0, NULL);
    context = dex_await_object (future, &error);

    To run a build we need to get the build manager service. That is available from the context with the :build-manager property.

    g_autoptr(FoundryBuildManager) build_manager = NULL;
    
    build_manager = foundry_context_dup_build_manager (context);

    One thing you’ll notice in Foundry is that many getters take a reference to the returned value. This is because Foundry heavily uses fibers and it is always better to own your objects when you cross fiber suspension points. This is where the dup_ prefix comes from instead of get_ .

    Building the project is quite simple too. Just await until it has completed.

    dex_await (foundry_build_manager_build (build_manager), &error);

    Running with Libfoundry

    To run is quite similar. Except you use the run manager instead of the build manager.

    g_autoptr(FoundryRunManager) run_manager = NULL;
    
    run_manager = foundry_context_dup_run_manager (context);
    dex_await (foundry_run_manager_run (run_manager), &error));

    There are of course more detailed ways to do this if you need precise control over things like where the project is deployed, such as to an external device. Or perhaps you want to control what command is run. The run manager and build manager also allows controlling the PTY that is used for both operations.

    Hopefully that is just enough to get you excited about using the tooling. The API has been obsessed over but it could use more documentation of which this is the infancy.