Skip to content

Trial cargo-wasi #121

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,10 @@ jobs:
toolchain: nightly-2021-03-25
override: true
components: rustfmt, clippy
target: wasm32-unknown-emscripten
- name: Cache .cargo
id: cache-primes
uses: actions/cache@v2
target: wasm32-wasi
- uses: actions-rs/[email protected]
with:
path: ~/.cargo
key: ${{ runner.os }}-${{ hashFiles('Cargo**') }}
- name: Install rust script
uses: actions-rs/cargo@v1
with:
command: install
args: cargo-web
crate: cargo-wasi
use-tool-cache: true
- name: Install deps
run: |
Expand Down
8 changes: 4 additions & 4 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ EMMAKEN_CFLAGS = "-s ERROR_ON_UNDEFINED_SYMBOLS=0 -s ALLOW_MEMORY_GROWTH=1 -s TO
clear = true
dependencies = ['prebuild']
command = "cargo"
args = ["build", "--tests", "--target", "wasm32-unknown-emscripten"]
args = ["wasi", "build", "--tests"]

[tasks.deploy]
dependencies = ["ci-flow"]
command = "cargo"
args = ["web", "deploy", "--use-system-emscripten"]
args = ["wasi", "deploy"]

[tasks.docs]
dependencies = ["prebuild"]
Expand All @@ -19,7 +19,7 @@ args = ["doc", "--target", "wasm32-unknown-emscripten", "--bins", "--document-pr

[tasks.expand]
command = "cargo"
args = ["expand", "--target", "wasm32-unknown-emscripten", ">", "output.rs"]
args = ["expand", "--target", "wasm32-wasi", ">", "output.rs"]

[tasks.prebuild]
condition = { files_not_exist = ["${CARGO_MAKE_WORKING_DIRECTORY}/target/duckdb.wasm", "${CARGO_MAKE_WORKING_DIRECTORY}/target/duckdb.hpp"] }
Expand All @@ -35,4 +35,4 @@ args = ["web", "start"]
clear = true
dependencies = ['build']
command = "cargo"
args = ["web", "test", "--nodejs", "--use-system-emscripten", "--", "--nocapture"]
args = ["wasi", "test", "--nodejs", "--", "--nocapture"]
109 changes: 57 additions & 52 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,78 +1,83 @@
#![feature(try_trait)]

use std::env::{join_paths, set_var, split_paths, var};
use std::path::PathBuf;
use which::which;

fn eat(command: &mut std::process::Command) {
let res = command.output().expect("Compile");

if !res.status.success() {
panic!("{}", String::from_utf8(res.stderr).expect("String"));
}
fn exists(s: String) -> String {
let path = std::path::Path::new(&s);
assert_eq!(path.exists(), true, "{}", &s);
return path.to_string_lossy().to_string();
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
// TODO: reenable
// println!("cargo:rustc-link-lib=static-nobundle=stdc++");
let emcc_path = which("emcc").expect("emar");
let emscripten_path = emcc_path.parent().unwrap();

let emar_path =
which("emar").expect("Couldn't find emar, is the emscripten environment activated?");
let clang_path = emscripten_path.parent().unwrap().join("bin");

eat(cc::Build::new()
.get_compiler()
.to_command()
.arg("-fvisibility=default")
.arg("-fPIC")
.arg("-DDUCKDB_NO_THREADS=1")
.arg("-sWASM=1")
.arg("-DDUCKDB_BUILD_LIBRARY=1")
.arg("-sWARN_ON_UNDEFINED_SYMBOLS=1")
.arg("-sALLOW_MEMORY_GROWTH=1")
.arg("-sUSE_PTHREADS=0")
.arg("-sDISABLE_EXCEPTION_CATCHING=0")
.arg("-fexceptions")
.arg("-Wno-unused-parameter")
.arg("--no-entry")
.arg("-shared")
.arg("src/reexporter.cpp")
.arg("-Itarget")
// .arg("target/duckdb.wasm")
.arg("target/duckdb.cpp")
.arg("-o")
.arg("duckdb.o"));
let mut path = split_paths(&var("PATH").unwrap()).collect::<Vec<PathBuf>>();
path.push((*clang_path.to_string_lossy()).into());
eprintln!("{:?}", path);
set_var("PATH", join_paths(path)?);

println!("{:?}", &emar_path);
eat(std::process::Command::new(&emar_path)
.arg("rcs")
.arg("target/libduckdb.a")
.arg("duckdb.o"));

println!("cargo:rustc-link-lib=static-nobundle=duckdb");
println!(
"cargo:rustc-link-search={}",
std::env::current_dir()?
.join("target")
.to_str()
.expect("aaaaa")
);
cc::Build::new()
.flag("-fvisibility=default")
.flag("-fPIC")
.flag("-DDUCKDB_NO_THREADS=1")
.flag("-DDUCKDB_BUILD_LIBRARY=1")
.flag("-fexceptions")
.flag("-Wno-unused-parameter")
//.cpp(true)
.flag("-shared")
.flag("-std=gnu++17")
.file("src/reexporter.cpp")
.include(exists(format!(
"{}/system/lib/libcxx/include",
emscripten_path.display()
)))
.include(exists(format!(
"{}/system/lib/libcxxabi/include",
emscripten_path.display()
)))
.include(exists(format!(
"{}/system/include",
emscripten_path.display()
)))
.include(exists(format!(
"{}/system/lib/libc/musl/include",
emscripten_path.display()
)))
.include(exists(format!(
"{}/system/lib/libc/musl/arch/emscripten",
emscripten_path.display()
)))
.include(exists(format!(
"{}/system/lib/libc/musl/arch/generic",
emscripten_path.display()
)))
.include("target")
.file("target/duckdb.cpp")
.compile("duckdb");

#[cfg(windows)]
{
let p = emar_path.parent().unwrap().parent().unwrap().join("bin");

println!("{:?}", p);
std::env::set_var("LIBCLANG_PATH", &p);
println!("{:?}", clang_path);
std::env::set_var("LIBCLANG_PATH", &clang_path);
}

bindgen::builder()
.header("target/duckdb.h")
// .detect_include_paths(true)
.detect_include_paths(true)
/*
.clang_arg(format!(
"-I{}",
emar_path
emscripten_path
.join("../cache/sysroot/include")
.to_str()
.expect("include path")
))
*/
.generate_block(true)
.rustified_enum(".*")
// .clang_arg("-DDUCKDB_BUILD_LIBRARY")
Expand Down
1 change: 0 additions & 1 deletion src/reexporter.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <emscripten.h>
#include "duckdb.hpp"
#include <iostream>

Expand Down