ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.65k stars 2.53k forks source link

Zig 0.9.0 Regression: can't import <core_cm3.h> #10440

Open foldl opened 2 years ago

foldl commented 2 years ago

Zig Version

0.9.0

Steps to Reproduce

0.9.0 fails to import while 0.8.0 is OK.

  1. aaa.h

    #pragma once
    
    typedef enum IRQn
    {
    /* -------------------  Cortex-M3 Processor Exceptions Numbers  ------------------- */
      NonMaskableInt_IRQn           = -14,      /*!<  2 Non Maskable Interrupt          */
      HardFault_IRQn                = -13,      /*!<  3 HardFault Interrupt             */
      MemoryManagement_IRQn         = -12,      /*!<  4 Memory Management Interrupt     */
      BusFault_IRQn                 = -11,      /*!<  5 Bus Fault Interrupt             */
      UsageFault_IRQn               = -10,      /*!<  6 Usage Fault Interrupt           */
      SVCall_IRQn                   =  -5,      /*!< 11 SV Call Interrupt               */
      DebugMonitor_IRQn             =  -4,      /*!< 12 Debug Monitor Interrupt         */
      PendSV_IRQn                   =  -2,      /*!< 14 Pend SV Interrupt               */
      SysTick_IRQn                  =  -1,      /*!< 15 System Tick Interrupt           */
    } IRQn_Type;
    
    /* --------  Configuration of the Cortex-M3 Processor and Core Peripherals  ------- */
    #define __CM3_REV                 0x0201    /*!< Core revision r2p1                              */
    #define __MPU_PRESENT             0         /*!< MPU present or not                              */
    #define __NVIC_PRIO_BITS          3         /*!< Number of Bits used for Priority Levels         */
    #define __Vendor_SysTickConfig    0         /*!< Set to 1 if different SysTick Config is used    */
    
    #include <core_cm3.h>                       /* Processor and core peripherals                    */
  2. zbug.zig

    const cm3 = @cImport({
        @cInclude("aaa.h");
    });
    
    export fn tool() c_int {
        return cm3.HardFault_IRQn;
    }
  3. build zbug.zig

    zig build-obj -target thumb-freestanding-none -mcpu cortex_m3 -I CMSIS_INC_PATH -I . zbug.zig

Expected Behavior

It should compile.

Actual Behavior

Using 0.9.0:

.\zbug.zig:1:13: error: C import failed
const cm3 = @cImport({
            ^
.\zbug.zig:1:13: note: libc headers not available; compilation does not link against libc
const cm3 = @cImport({
            ^
.../CMSIS/Include\core_cm3.h:138:6: note: "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
    #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
     ^
.\zbug.zig:6:12: note: referenced here
    return cm3.HardFault_IRQn;
           ^
foldl commented 2 years ago

It's reported because defined (__VFP_FP__) && !defined(__SOFTFP__) for Cortex M3. Code of core_cm3.h:

https://github.com/ARM-software/CMSIS/blob/f2cad4345783c948ed4a7f5cdb02cdc0856366f1/CMSIS/Include/core_cm3.h#L138