Skip to content

Instantly share code, notes, and snippets.

@Kerollmops
Last active January 21, 2018 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kerollmops/7d6e84c0312f8c02a187631b13a15231 to your computer and use it in GitHub Desktop.
Save Kerollmops/7d6e84c0312f8c02a187631b13a15231 to your computer and use it in GitHub Desktop.
extern crate bindgen;
use std::env;
use std::path::{Path, PathBuf};
fn main() {
println!("cargo:rustc-link-search=framework=/System/Library/Frameworks/");
println!("cargo:rustc-link-lib=framework=OpenCL");
let headers = env::var("CARGO_MANIFEST_DIR").unwrap() + "/opencl22/CL/";
let headers = Path::new(&headers);
let bindings = bindgen::Builder::default()
.link_framework("OpenCL")
// .clang_arg("-framework OpenCL")
.header(headers.join("opencl.h").to_string_lossy())
.generate()
.expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}
Compiling opencl-sys v0.1.0 (file:///.../linen/opencl-sys)
error: failed to run custom build command for `opencl-sys v0.1.0 (file:///.../linen/opencl-sys)`
process didn't exit successfully: `.../linen/target/debug/build/opencl-sys-39388fb3de4cc39f/build-script-build` (exit code: 101)
--- stdout
cargo:rustc-link-search=framework=/System/Library/Frameworks/
cargo:rustc-link-lib=framework=OpenCL
--- stderr
.../linen/opencl-sys/opencl22/CL/opencl.h:40:10: fatal error: 'OpenCL/cl.h' file not found
.../linen/opencl-sys/opencl22/CL/opencl.h:40:10: fatal error: 'OpenCL/cl.h' file not found, err: true
thread 'main' panicked at 'Unable to generate bindings: ()', libcore/result.rs:916:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.
// compile me with: clang -framework OpenCL -o test test.c
#include <stdio.h>
#include <stdlib.h>
// #include <OpenCL/opencl.h>
#include "opencl22/CL/opencl.h"
int main(int argc, char* const argv[]) {
cl_uint num_devices, i;
clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, 0, NULL, &num_devices);
cl_device_id* devices = calloc(sizeof(cl_device_id), num_devices);
clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, num_devices, devices, NULL);
char buf[128];
for (i = 0; i < num_devices; i++) {
clGetDeviceInfo(devices[i], CL_DEVICE_NAME, 128, buf, NULL);
fprintf(stdout, "Device %s supports ", buf);
clGetDeviceInfo(devices[i], CL_DEVICE_VERSION, 128, buf, NULL);
fprintf(stdout, "%s\n", buf);
}
free(devices);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment