douweschulte / pdbtbx

A library to open/edit/save (crystallographic) Protein Data Bank (PDB) and mmCIF files in Rust.
https://crates.io/crates/pdbtbx
MIT License
49 stars 12 forks source link

Produce js package #91

Closed sverhoeven closed 2 years ago

sverhoeven commented 2 years ago

Trying to build this rust package into a js package using https://github.com/rustwasm/wasm-pack

curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
wasm-pack build
output ``` [INFO]: Checking for the Wasm target... [INFO]: Compiling to Wasm... Compiling pdbtbx v0.9.1 (/home/verhoes/git/vre4imbc/pdbtbx) error[E0277]: the trait bound `std::string::String: std::marker::Copy` is not satisfied --> src/structs/pdb.rs:39:21 | 39 | pub identifier: Option, | ^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `std::string::String` | = note: required because of the requirements on the impl of `std::marker::Copy` for `std::option::Option` note: required by a bound in `__wbg_get_pdb_identifier::assert_copy` --> src/structs/pdb.rs:11:1 | 11 | #[wasm_bindgen] | ^^^^^^^^^^^^^^^ required by this bound in `__wbg_get_pdb_identifier::assert_copy` = note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `transformation::TransformationMatrix: std::marker::Copy` is not satisfied --> src/structs/pdb.rs:43:16 | 43 | pub scale: Option, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `transformation::TransformationMatrix` | = note: required because of the requirements on the impl of `std::marker::Copy` for `std::option::Option` note: required by a bound in `__wbg_get_pdb_scale::assert_copy` --> src/structs/pdb.rs:11:1 | 11 | #[wasm_bindgen] | ^^^^^^^^^^^^^^^ required by this bound in `__wbg_get_pdb_scale::assert_copy` = note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `transformation::TransformationMatrix: std::marker::Copy` is not satisfied --> src/structs/pdb.rs:45:16 | 45 | pub origx: Option, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `transformation::TransformationMatrix` | = note: required because of the requirements on the impl of `std::marker::Copy` for `std::option::Option` note: required by a bound in `__wbg_get_pdb_origx::assert_copy` --> src/structs/pdb.rs:11:1 | 11 | #[wasm_bindgen] | ^^^^^^^^^^^^^^^ required by this bound in `__wbg_get_pdb_origx::assert_copy` = note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `unit_cell::UnitCell: std::marker::Copy` is not satisfied --> src/structs/pdb.rs:49:20 | 49 | pub unit_cell: Option, | ^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `unit_cell::UnitCell` | = note: required because of the requirements on the impl of `std::marker::Copy` for `std::option::Option` note: required by a bound in `__wbg_get_pdb_unit_cell::assert_copy` --> src/structs/pdb.rs:11:1 | 11 | #[wasm_bindgen] | ^^^^^^^^^^^^^^^ required by this bound in `__wbg_get_pdb_unit_cell::assert_copy` = note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `symmetry::Symmetry: std::marker::Copy` is not satisfied --> src/structs/pdb.rs:51:19 | 51 | pub symmetry: Option, | ^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `symmetry::Symmetry` | = note: required because of the requirements on the impl of `std::marker::Copy` for `std::option::Option` note: required by a bound in `__wbg_get_pdb_symmetry::assert_copy` --> src/structs/pdb.rs:11:1 | 11 | #[wasm_bindgen] | ^^^^^^^^^^^^^^^ required by this bound in `__wbg_get_pdb_symmetry::assert_copy` = note: this error originates in the attribute macro `wasm_bindgen` (in Nightly builds, run with -Z macro-backtrace for more info) For more information about this error, try `rustc --explain E0277`. error: could not compile `pdbtbx` due to 5 previous errors Error: Compiling your crate to WebAssembly failed Caused by: failed to execute `cargo build`: exited with exit status: 101 full command: "cargo" "build" "--lib" "--release" "--target" "wasm32-unknown-unknown" ```

For now getting the trait 'std::marker::Copy' is not implemented errors. And probably breaks the original build target.

douweschulte commented 2 years ago

I am not well versed in wasm, so I will have to look into the Copy requirement and how to handle that properly. For the new build target I would propose to do that behind a feature.

sverhoeven commented 2 years ago

Stopping this. Instead of putting wasm target inside, better to use crate in another repo. See https://github.com/i-VRESSE/pdbtbx-ts#test-from-js