#Conditional compilation for c source

1 messages · Page 1 of 1 (latest)

spice junco
#

How does one use Options for Conditional Compilation in the context of move @cImport to the build system?

Specifically, I want to follow the upgrade path described in this comment except ziggy-pydust/pydust/src/ffi.zig looks like this:

const pyconf = @import("pyconf");

pub usingnamespace @cImport({
    if (pyconf.limited_api) {
        @cDefine("Py_LIMITED_API", pyconf.hexversion);
    }
    @cDefine("PY_SSIZE_T_CLEAN", {});
    @cInclude("Python.h");

    // From 3.12 onwards, structmember.h is fixed to be including in Python.h
    // See https://github.com/python/cpython/pull/99014
    @cInclude("structmember.h");
});

Right now, translate-c generates the following C:

#define Py_LIMITED_API 0x030d00f0
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <structmember.h>

Should I combine addTranslateCImport (like in this example) with std.fmt.comptimePrint?

GitHub

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software. - Issues · ziglang/zig

GitHub

A toolkit for building Python extensions in Zig. Contribute to spiraldb/ziggy-pydust development by creating an account on GitHub.

GitHub

This issue is to remove the @cImport language builtin, instead relying on the feature being provided by the build system (std.Build.Step.TranslateC). This removes one dependency on libclang inside ...

spice junco