Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including libxml2 with a LLVM module map

When trying to build a Swift package I created that uses a LLVM module map to include libxml2 from /usr/include/libxml2/, I get the following error:

Compiling Swift Module 'foo' (1 sources)
<module-includes>2:9: note: in file included from <module-includes>:2: 
#import "/usr/include/libxml2/libxml/catalog.h"

/usr/include/libxml2/libxml/catalog.h:22:10: error: 'libxml/xmlversion.h' file not found

This is my module map:

module Clibxml2 [system] {

    umbrella "/usr/include/libxml2"
    export *
}

My dummy main.swift file only tries to import the module for now:

import Clibxml2

It compiles when I try to use another header path / umbrella (e.g. /usr/include/CommonCrypto). I verified that xmlversion.h does exist in /usr/include/libxml2/libxml. Am I missing something?

like image 449
Nicolai Avatar asked Nov 10 '22 00:11

Nicolai


1 Answers

Swift has an -Xcc option now which can be used to pass additional compiler flags:

swift build -Xcc -I/usr/include/libxml2
like image 97
nwellnhof Avatar answered Dec 09 '22 12:12

nwellnhof