Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document encoding is not compiling on linux #115

Open
gazsiazasz opened this issue May 1, 2021 · 2 comments
Open

Document encoding is not compiling on linux #115

gazsiazasz opened this issue May 1, 2021 · 2 comments

Comments

@gazsiazasz
Copy link

On the system libxml2-dev package is installed, and
/usr/include/libxml -> /usr/include/libxml2/libxml symlinked and
/usr/include/libxml2/module.modulemap exists with the following content:

module libxml2 [system] [extern_c] {
    link "xml2"

    umbrella "libxml"
    export *
    module * { export * }
    exclude header "libxml/DOCBparser.h"
}

If I create a template swift package with Fuzi as a dependency in it:

// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "spm-test",
    products: [
        // Products define the executables and libraries a package produces, and make them visible to other packages.
        .library(
            name: "spm-test",
            targets: ["spm-test"]),
    ],
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        // .package(url: /* package url */, from: "1.0.0"),
        .package(url: "https://github.com/cezheng/Fuzi.git", from: "3.1.2"),
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages this package depends on.
        .target(
            name: "spm-test",
            dependencies: ["Fuzi"]),
        .testTarget(
            name: "spm-testTests",
            dependencies: ["spm-test"]),
    ]
)

Compilation is failing on the following code snippet:

open fileprivate(set) lazy var encoding: String.Encoding = {
if let encodingName = ^-^self.cDocument.pointee.encoding {
let encoding = CFStringConvertIANACharSetNameToEncoding(encodingName as CFString?)
if encoding != kCFStringEncodingInvalidId {
return String.Encoding(rawValue: UInt(CFStringConvertEncodingToNSStringEncoding(encoding)))
}
}
return String.Encoding.utf8
}()

The error message I get is this:

/home/pi/spm-test/.build/checkouts/Fuzi/Sources/Document.swift:36:22: error: cannot find 'CFStringConvertIANACharSetNameToEncoding' in scope
      let encoding = CFStringConvertIANACharSetNameToEncoding(encodingName as CFString?)
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/pi/spm-test/.build/checkouts/Fuzi/Sources/Document.swift:37:22: error: cannot find 'kCFStringEncodingInvalidId' in scope
      if encoding != kCFStringEncodingInvalidId {
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~
/home/pi/spm-test/.build/checkouts/Fuzi/Sources/Document.swift:38:47: error: cannot find 'CFStringConvertEncodingToNSStringEncoding' in scope
        return String.Encoding(rawValue: UInt(CFStringConvertEncodingToNSStringEncoding(encoding)))
                                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/pi/spm-test/.build/checkouts/Fuzi/Sources/Document.swift:36:22: error: cannot find 'CFStringConvertIANACharSetNameToEncoding' in scope
      let encoding = CFStringConvertIANACharSetNameToEncoding(encodingName as CFString?)
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/pi/spm-test/.build/checkouts/Fuzi/Sources/Document.swift:37:22: error: cannot find 'kCFStringEncodingInvalidId' in scope
      if encoding != kCFStringEncodingInvalidId {
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~
/home/pi/spm-test/.build/checkouts/Fuzi/Sources/Document.swift:38:47: error: cannot find 'CFStringConvertEncodingToNSStringEncoding' in scope
        return String.Encoding(rawValue: UInt(CFStringConvertEncodingToNSStringEncoding(encoding)))

I saw that Kanna has something to patch this behavior but I am not sure how to implement it:

https://github.com/tid-kijyun/Kanna/blob/c657fb9f5827ef138068215c76ad0bb62bbc92da/Sources/Kanna/libxmlHTMLDocument.swift#L29

@nighthawk
Copy link

Do you by any chance have an example file which requires this code path? Then I can add this to my PR #117. Currently that PR just disables this code path on Linux.

@jeffdav
Copy link

jeffdav commented Sep 6, 2024

FYI, I just put up #129 which replaces usage of CoreFoundation with a simple String.Encoding extension that does the same mapping. That PR is for Windows support, but that probably fixes this issue on Linux as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants