Giter Site home page Giter Site logo

swift-llvm-bindings's Issues

How do I use `llvm::Function` through Swift bindings?

Apologies if I'm asking on the wrong place, because it's maybe more of a C++ inter-op question.

I'm trying to use llvm::Function through LLVM_Utils and/or LLVM_IR. Xcode's auto-completion shows this, which is confusing to me:

image

Then, when I try to build it, I get this error:

'Function' is not a member type of enum '__ObjC.llvm'

In the swift-llvm-bindings source is this line:

https://github.com/apple/swift-llvm-bindings/blob/b9b825218a945e450cbaf740a980284b323e09ca/Sources/LLVM/LLVM_Utils.swift#L58

Both Twine and Function are classes declared in the llvm namespace. The only difference is the LLVM_EXTERNAL_VISIBILITY macro for Function, but it expands to just [[gnu::visibility("default")]] on macOS.

Why does llvm.Twine work, but not llvm.Function? What should I do to make llvm.Function work?

Regarding the building resource in `Package.swift`

It looks like the module map file is usually referenced as <llvm_root>/llvm/include/module.modulemap and the line 17 in the Package.swift doesn't seem to locate the module map correctly. That is, the llvmModuleMapPath is resolved as <llvm_root>/llvm/include/llvm/module.modulemap and doesn't match where the module map usually is.

    guard let llvmHeaderPath = env["SWIFT_LLVM_BINDINGS_PATH_TO_LLVM_HEADERS"] else {
        print("please pass an environment variable to swift-package: " +
              "SWIFT_LLVM_BINDINGS_PATH_TO_LLVM_HEADERS " +
              "(e.g. swift/llvm-project/llvm/include)")
        return nil
    }
    let llvmModuleMapPath = "\(llvmHeaderPath)/llvm/module.modulemap". // line 17

I am quite new to LLVM and am very likely to be wrong. If without llvm is intended, I can open a pr to fix it. :)

Modules not found when used as a SwiftPM dependency

I'm able to build the project standalone using SwiftPM with no problems (or at least I think there is no problem). However, when I use it as a dependency, SwiftPM reports errors of missing modules.

When I build the depending package like this on the command line,

SWIFT_LLVM_BINDINGS_PATH_TO_LLVM_HEADERS=/path/to/LLVM/headers SWIFT_LLVM_BINDINGS_PATH_TO_LLVM_GENERATED_HEADERS=/path/to/LLVM/generated/headers swift build

it reports

error: missing required module 'LLVM_Utils'

at import SwiftLLVM_Utils.

When I build the depending project in Xcode, it reports

No such module 'SwiftLLVM_Utils'

also at import SwiftLLVM_Utils.

My toolchain is the 2024-02-15 trunk snapshot.

This is what my depending package's Package.swift looks like:

// swift-tools-version: 5.9

import Foundation
import PackageDescription

var environment = ProcessInfo.processInfo.environment

var swiftLLVMBindings: Package.Dependency {
    if environment["SWIFT_LLVM_BINDINGS_PATH_TO_LLVM_HEADERS"] != nil && environment["SWIFT_LLVM_BINDINGS_PATH_TO_LLVM_GENERATED_HEADERS"] != nil {
        return .package(url: "https://github.com/apple/swift-llvm-bindings.git", branch: "llvm.org/main")
    } else {
        return .package(path: "/local/copy/with/correct/includes")
    }
}


let package = Package(
    name: "depending-package",
    products: [.library(name: "depending-package", targets: ["depending-package"]),],
    dependencies: [swiftLLVMBindings],
    targets: [
        .target(
            name: "depending-package",
            dependencies: [.product(name: "SwiftLLVM_Utils", package: "swift-llvm-bindings"),],
            swiftSettings: [.interoperabilityMode(.Cxx),]
        ),
        .testTarget(
            name: "depending-packageTests",
            dependencies: ["depending-package"]
        ),
    ]
)

What should I do in order to use the project as a dependency?

Is this still actively maintained?

Hi,

Just want to know if this project is still being maintained? I came from the LLVM Dev Mtg and this is really interesting.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.