Skip to content

[Bug] Missing compilation configuration in cpython package #8

@PhiAlex-baiye

Description

@PhiAlex-baiye

Problem

The Kaida-Amethyst/python/cpython dependency package lacks proper compilation configuration, causing Python header and library linking failures during testing and dependency compilation.

Error Messages

Header File Error

failed: /usr/bin/cc -o ... -I/home/cc/.moon/include -L/home/cc/.moon/lib -g -c ...
/home/cc/code/moon/matplotlib.mbt/.mooncakes/Kaida-Amethyst/python/cpython/wrap.c:2:10: 致命错误:Python.h:没有那个文件或目录
    2 | #include <Python.h>
      |          ^~~~~~~~~~
编译中断。

Linking Errors

undefined reference to `PyDict_Size'
undefined reference to `PyList_Append'
undefined reference to `PyTuple_Size'
undefined reference to `PyDict_New'
undefined reference to `PyFloat_FromDouble'
undefined reference to `PyLong_FromLong'
undefined reference to `PyList_New'
undefined reference to `PyTuple_New'
undefined reference to `PyObject_Str'
undefined reference to `PyErr_Print'
undefined reference to `PyErr_Clear'
undefined reference to `Py_IsInitialized'
undefined reference to `Py_Initialize'
undefined reference to `PyCallable_Check'

Impact

  • moon test fails completely
  • Any operation requiring full dependency tree compilation fails
  • Users cannot run tests even after installing python3-devel
  • Inconsistent behavior between moon run (works) and moon test (fails)

Root Cause

The package's moon.pkg.json at .mooncakes/Kaida-Amethyst/python/cpython/moon.pkg.json is missing the link configuration section.

Current Configuration

{
  "is-main": false,
  "supported-targets" : ["native"],
  "native-stub" : [
    "wrap.c"
  ]
}

Missing Configuration

The package needs proper compilation and linking flags to find Python headers and libraries.

Proposed Solutions

Option 1: Static Configuration (Quick Fix)

Add the link section with common Python paths:

{
  "is-main": false,
  "supported-targets" : ["native"],
  "native-stub" : [
    "wrap.c"
  ],
  "link" : {
    "native" : {
      "cc" : "gcc",
      "cc-flags": "-I/usr/include/python3.13 -DNDEBUG",
      "cc-link-flags" : "-L/usr/lib64 -lpython3.13 -ldl -lm"
    }
  }
}

Option 2: Dynamic Configuration (Recommended)

Use python3-config for cross-platform compatibility:

{
  "is-main": false,
  "supported-targets" : ["native"],
  "native-stub" : [
    "wrap.c"
  ],
  "link" : {
    "native" : {
      "cc" : "gcc",
      "cc-flags": "$(python3-config --includes) -DNDEBUG",
      "cc-link-flags" : "$(python3-config --ldflags)"
    }
  }
}

Option 3: Environment Variable Support

Allow configuration through environment variables:

{
  "is-main": false,
  "supported-targets" : ["native"],
  "native-stub" : [
    "wrap.c"
  ],
  "link" : {
    "native" : {
      "cc" : "${CC:-gcc}",
      "cc-flags": "${PYTHON_CFLAGS:-$(python3-config --includes)} -DNDEBUG",
      "cc-link-flags" : "${PYTHON_LDFLAGS:-$(python3-config --ldflags)}"
    }
  }
}

Environment

  • OS: Fedora 42
  • Python: 3.13.5
  • Python Headers: Installed via python3-devel
  • Compiler: gcc

Testing

After applying the fix, the following should work:

moon clean
moon test --target native

Alternative Workarounds

Users can currently work around this by manually editing the .mooncakes directory after each dependency update, but this is not sustainable.

Related Issues

This is the core technical issue that prevents proper compilation even when system dependencies are correctly installed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions