Fixed native build issues

pull/8/head
Benedikt Terhechte 2 years ago
parent 047552a20a
commit 2482151eeb

@ -1,2 +1,2 @@
[build]
target = "wasm32-unknown-unknown"
#target = "wasm32-unknown-unknown"

@ -16,7 +16,7 @@ export RUSTFLAGS=--cfg=web_sys_unstable_apis
rm -f web_demo/${CRATE_NAME_SNAKE_CASE}_bg.wasm
echo "Building rust…"
BUILD=debug
BUILD=release
if [[ "$BUILD" == "debug" ]]; then
cargo build -p ${CRATE_NAME} --lib --target wasm32-unknown-unknown
else

@ -0,0 +1,29 @@
#!/bin/sh
set -e
rm -rf ../target/release/bundle/osx/Postsack.app
# Build for x86 and ARM
cargo build --release --target=aarch64-apple-darwin
cargo build --release --target=x86_64-apple-darwin
# Combine into a fat binary
lipo -create ../target/aarch64-apple-darwin/release/postsack ../target/x86_64-apple-darwin/release/postsack -output postsack
# Perform Cargo bundle to create a macOS Bundle
cargo bundle --release
# Override bundle binary with the fat one
# Also: We want to have `Postsack` capitalized on macOS, so we rename
rm ../target/release/bundle/osx/Postsack.app/Contents/MacOS/postsack
mv ./postsack ../target/release/bundle/osx/Postsack.app/Contents/MacOS/
# Tell the Info.plist or binary is capitalized
/usr/libexec/PlistBuddy -c "Set :CFBundleExecutable Postsack" "../target/release/bundle/osx/Postsack.app/Contents/Info.plist"

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 46 KiB

Before

Width:  |  Height:  |  Size: 752 B

After

Width:  |  Height:  |  Size: 752 B

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 46 KiB

Before

Width:  |  Height:  |  Size: 151 KiB

After

Width:  |  Height:  |  Size: 151 KiB

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

Before

Width:  |  Height:  |  Size: 151 KiB

After

Width:  |  Height:  |  Size: 151 KiB

Before

Width:  |  Height:  |  Size: 519 KiB

After

Width:  |  Height:  |  Size: 519 KiB

@ -17,7 +17,7 @@ use eyre::Result;
use serde_json::Value;
use crate::database::{
database_like::DatabaseQuery,
database_like::{DatabaseLike, DatabaseQuery},
query::Query,
query_result::{QueryResult, QueryRow},
};
@ -38,6 +38,7 @@ pub(super) type OutputReciever<Context> = Receiver<Result<Response<Context>>>;
// FIXME: Instead of this wasm mess, two different link types?
pub(super) struct Link<Context: Send + 'static> {
#[cfg(target_arch = "wasm32")]
database: Box<dyn DatabaseQuery>,
#[cfg(not(target_arch = "wasm32"))]
@ -128,7 +129,7 @@ impl<Context: Send + Sync + 'static> Link<Context> {
}
#[cfg(not(target_arch = "wasm32"))]
pub(super) fn run<Context: Send + Sync + 'static, Database: DatabaseQuery>(
pub(super) fn run<Context: Send + Sync + 'static, Database: DatabaseLike + DatabaseQuery>(
config: &Config,
) -> Result<Link<Context>> {
// Create a new database connection, just for reading

@ -9,7 +9,7 @@ use super::sql::*;
use super::{value_from_field, RowConversion};
use ps_core::{
crossbeam_channel::{unbounded, Sender},
Config, DBMessage, DatabaseLike, EmailEntry, OtherQuery, Query, QueryResult,
Config, DBMessage, DatabaseLike, DatabaseQuery, EmailEntry, OtherQuery, Query, QueryResult,
};
#[derive(Debug)]
@ -25,6 +25,43 @@ impl Clone for Database {
}
}
impl DatabaseQuery for Database {
fn query(&self, query: &Query) -> Result<Vec<QueryResult>> {
use rusqlite::params_from_iter;
let c = match &self.connection {
Some(n) => n,
None => bail!("No connection to database available in query"),
};
let (sql, values) = query.to_sql();
let mut stmt = c.prepare(&sql)?;
let mut query_results = Vec::new();
let mut converted = Vec::new();
for value in values {
converted.push(super::conversion::json_to_value(&value)?);
}
let p = params_from_iter(converted.iter());
let mut rows = stmt.query(p)?;
while let Some(row) = rows.next()? {
match query {
Query::Grouped { group_by, .. } => {
let result = QueryResult::grouped_from_row(group_by, row)?;
query_results.push(result);
}
Query::Normal { fields, .. } => {
let result = QueryResult::from_row(fields, row)?;
query_results.push(result);
}
Query::Other {
query: OtherQuery::All(field),
} => query_results.push(QueryResult::Other(value_from_field(field, row)?)),
}
}
Ok(query_results)
}
}
impl DatabaseLike for Database {
/// Open database at path `Path`.
fn new(path: impl AsRef<Path>) -> Result<Self> {
@ -72,41 +109,6 @@ impl DatabaseLike for Database {
self.insert_config_fields(fields)
}
fn query(&self, query: &Query) -> Result<Vec<QueryResult>> {
use rusqlite::params_from_iter;
let c = match &self.connection {
Some(n) => n,
None => bail!("No connection to database available in query"),
};
let (sql, values) = query.to_sql();
let mut stmt = c.prepare(&sql)?;
let mut query_results = Vec::new();
let mut converted = Vec::new();
for value in values {
converted.push(super::conversion::json_to_value(&value)?);
}
let p = params_from_iter(converted.iter());
let mut rows = stmt.query(p)?;
while let Some(row) = rows.next()? {
match query {
Query::Grouped { group_by, .. } => {
let result = QueryResult::grouped_from_row(group_by, row)?;
query_results.push(result);
}
Query::Normal { fields, .. } => {
let result = QueryResult::from_row(fields, row)?;
query_results.push(result);
}
Query::Other {
query: OtherQuery::All(field),
} => query_results.push(QueryResult::Other(value_from_field(field, row)?)),
}
}
Ok(query_results)
}
/// Begin the data import.
/// This will consume the `Database`. A new one has to be opened
/// afterwards in order to support multi-threading.

Loading…
Cancel
Save