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

feat: Support build target for multiple platforms #70

Closed
idranme opened this issue May 1, 2022 · 7 comments
Closed

feat: Support build target for multiple platforms #70

idranme opened this issue May 1, 2022 · 7 comments

Comments

@idranme
Copy link

idranme commented May 1, 2022

At present, the compiled library can only be used for a single platform. If you want to support cross platform, you need to build multiple sets of code. This adds a lot of tedious work.

@idranme
Copy link
Author

idranme commented May 1, 2022

It would be better to generate unified glue code after building libraries for multiple platforms.

@littledivy
Copy link
Member

You can cross-compile to other platforms, deno_bindgen invokes cargo build internally - arguments after -- are passed to Cargo. It's a common practice to use Github CI to compile and distribute via Github releases. https://github.com/denoland/deno_bindgen#cli

This is similar to using similar workflows for publishing NAPI modules with napi-rs
For example, see https://github.com/littledivy/deno_audio/blob/main/.github/workflows/release.yml

If you don't want to use the CI, consider using cross or similar tools to achieve Rust cross-compilation.

It would be better to generate unified glue code after building libraries for multiple platforms.

I'm not sure what you mean by "unified glue code". It is already unified / same for all platforms.

@idranme
Copy link
Author

idranme commented May 1, 2022

You can cross-compile to other platforms, deno_bindgen invokes cargo build internally - arguments after -- are passed to Cargo. It's a common practice to use Github CI to compile and distribute via Github releases. https://github.com/denoland/deno_bindgen#cli

This is similar to using similar workflows for publishing NAPI modules with napi-rs For example, see https://github.com/littledivy/deno_audio/blob/main/.github/workflows/release.yml

If you don't want to use the CI, consider using cross or similar tools to achieve Rust cross-compilation.

It would be better to generate unified glue code after building libraries for multiple platforms.

I'm not sure what you mean by "unified glue code". It is already unified / same for all platforms.

thanks, I have a problem

@idranme
Copy link
Author

idranme commented May 1, 2022

let libSuffix = "";
switch (Deno.build.os) {
  case "windows":
    libSuffix = "dll";
    break;
  case "darwin":
    libSuffix = "dylib";
    break;
  case "linux":
    libSuffix = "so";
    break;
}

const libName = `./libadd.${libSuffix}`;
// Open library and define exported symbols
const dylib = Deno.dlopen(libName, {
  "add": { parameters: ["isize", "isize"], result: "isize" },
});

@idranme
Copy link
Author

idranme commented May 1, 2022

"bindings.ts" may be able to judge that the platform loads the corresponding library like the above code

@littledivy
Copy link
Member

It does that already using x/plug: https://deno.land/x/plug@0.5.1/plug.ts#L35

@idranme
Copy link
Author

idranme commented May 1, 2022

It does that already using x/plug: https://deno.land/x/plug@0.5.1/plug.ts#L35

well, thanks

@idranme idranme closed this as completed May 1, 2022
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

2 participants