mirror of
https://github.com/maplibre/maplibre-rs.git
synced 2025-12-08 19:05:57 +00:00
Add conditional compilation
This commit is contained in:
parent
2f4c05f2b4
commit
156e63daf4
@ -72,7 +72,7 @@ let baseConfig = {
|
||||
|
||||
let config = {
|
||||
...baseConfig,
|
||||
entryPoints: ['src/index.ts'],
|
||||
entryPoints: multithreaded ? ['src/sync/index.ts'] : ['src/unsync/index.ts'],
|
||||
incremental: argv.watch,
|
||||
plugins: [
|
||||
inlineWorker({
|
||||
@ -112,9 +112,10 @@ const emitTypeScript = () => {
|
||||
"tsc",
|
||||
"--",
|
||||
"-m", "es2022",
|
||||
"--project", multithreaded ? `${getLibDirectory()}/tsconfig.sync.json` : `${getLibDirectory()}/tsconfig.unsync.json`,
|
||||
"-outDir", outDirectory,
|
||||
"--declaration",
|
||||
"--emitDeclarationOnly"
|
||||
|
||||
], {
|
||||
cwd: '.',
|
||||
stdio: 'inherit',
|
||||
|
||||
6
web/lib/src/canvas.ts
Normal file
6
web/lib/src/canvas.ts
Normal file
@ -0,0 +1,6 @@
|
||||
export const preventDefaultTouchActions = () => {
|
||||
document.body.querySelectorAll("canvas").forEach(canvas => {
|
||||
canvas.addEventListener("touchstart", e => e.preventDefault())
|
||||
canvas.addEventListener("touchmove", e => e.preventDefault())
|
||||
})
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
import init from "./wasm/maplibre";
|
||||
|
||||
export const initialize = async (wasmPath: string) => {
|
||||
if (MULTITHREADED) {
|
||||
await initializeSharedModule(wasmPath)
|
||||
} else {
|
||||
// @ts-ignore
|
||||
await init(wasmPath)
|
||||
}
|
||||
}
|
||||
|
||||
export const initializeExisting = async (module: string, memory?: string) => {
|
||||
if (MULTITHREADED) {
|
||||
// @ts-ignore
|
||||
await init(module, memory)
|
||||
} else {
|
||||
// @ts-ignore
|
||||
await init(module)
|
||||
}
|
||||
}
|
||||
|
||||
const initializeSharedModule = async (wasmPath) => {
|
||||
let MEMORY_PAGES = 16 * 1024
|
||||
|
||||
const memory = new WebAssembly.Memory({initial: 1024, maximum: MEMORY_PAGES, shared: true})
|
||||
// @ts-ignore
|
||||
await init(wasmPath, memory)
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
import {initializeExisting} from "./module";
|
||||
|
||||
onmessage = async message => {
|
||||
|
||||
}
|
||||
@ -1,18 +1,17 @@
|
||||
import {create_pool_scheduler, run} from "./wasm/maplibre"
|
||||
import {create_pool_scheduler, run} from "../wasm/maplibre"
|
||||
import {Spector} from "spectorjs"
|
||||
// @ts-ignore esbuild plugin is handling this
|
||||
import MultithreadedPoolWorker from './multithreaded-pool.worker.js';
|
||||
import {checkRequirements, checkWasmFeatures} from "../browser";
|
||||
import init from "../wasm/maplibre";
|
||||
import {preventDefaultTouchActions} from "../canvas";
|
||||
// @ts-ignore esbuild plugin is handling this
|
||||
import PoolWorker from './pool.worker.js';
|
||||
|
||||
import {initialize} from "./module";
|
||||
import {checkRequirements, checkWasmFeatures} from "./browser";
|
||||
const initializeSharedModule = async (wasmPath) => {
|
||||
let MEMORY_PAGES = 16 * 1024
|
||||
|
||||
const preventDefaultTouchActions = () => {
|
||||
document.body.querySelectorAll("canvas").forEach(canvas => {
|
||||
canvas.addEventListener("touchstart", e => e.preventDefault())
|
||||
canvas.addEventListener("touchmove", e => e.preventDefault())
|
||||
})
|
||||
const memory = new WebAssembly.Memory({initial: 1024, maximum: MEMORY_PAGES, shared: true})
|
||||
// @ts-ignore
|
||||
await init(wasmPath, memory)
|
||||
}
|
||||
|
||||
export const startMapLibre = async (wasmPath: string | undefined, workerPath: string | undefined) => {
|
||||
@ -32,14 +31,12 @@ export const startMapLibre = async (wasmPath: string | undefined, workerPath: st
|
||||
|
||||
preventDefaultTouchActions();
|
||||
|
||||
await initialize(wasmPath);
|
||||
await initializeSharedModule(wasmPath);
|
||||
|
||||
const schedulerPtr = create_pool_scheduler(() => {
|
||||
let CurrentWorker = MULTITHREADED ? MultithreadedPoolWorker : PoolWorker;
|
||||
|
||||
return workerPath ? new Worker(workerPath, {
|
||||
type: 'module'
|
||||
}) : CurrentWorker();
|
||||
}) : PoolWorker();
|
||||
})
|
||||
|
||||
await run(schedulerPtr)
|
||||
@ -1,5 +1,8 @@
|
||||
import {worker_entry} from "./wasm/maplibre"
|
||||
import {initializeExisting} from "./module";
|
||||
import init, {worker_entry} from "../wasm/maplibre"
|
||||
|
||||
const initializeExisting = async (module: string, memory?: string) => {
|
||||
await init(module, memory)
|
||||
}
|
||||
|
||||
onmessage = async message => {
|
||||
const initialised = initializeExisting(message.data[0], message.data[1]).catch(err => {
|
||||
35
web/lib/src/unsync/index.ts
Normal file
35
web/lib/src/unsync/index.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import init, {create_pool_scheduler, run} from "../wasm/maplibre"
|
||||
import {Spector} from "spectorjs"
|
||||
import {checkRequirements, checkWasmFeatures} from "../browser";
|
||||
import {preventDefaultTouchActions} from "../canvas";
|
||||
// @ts-ignore esbuild plugin is handling this
|
||||
import PoolWorker from './pool.worker.js';
|
||||
|
||||
export const startMapLibre = async (wasmPath: string | undefined, workerPath: string | undefined) => {
|
||||
await checkWasmFeatures()
|
||||
|
||||
let message = checkRequirements();
|
||||
|
||||
if (message) {
|
||||
console.error(message)
|
||||
alert(message)
|
||||
return
|
||||
}
|
||||
|
||||
if (WEBGL) {
|
||||
let spector = new Spector()
|
||||
spector.displayUI()
|
||||
}
|
||||
|
||||
preventDefaultTouchActions();
|
||||
|
||||
await init(wasmPath);
|
||||
|
||||
const schedulerPtr = create_pool_scheduler(() => {
|
||||
return workerPath ? new Worker(workerPath, {
|
||||
type: 'module'
|
||||
}) : PoolWorker();
|
||||
})
|
||||
|
||||
await run(schedulerPtr)
|
||||
}
|
||||
3
web/lib/src/unsync/pool.worker.ts
Normal file
3
web/lib/src/unsync/pool.worker.ts
Normal file
@ -0,0 +1,3 @@
|
||||
onmessage = async message => {
|
||||
|
||||
}
|
||||
@ -13,5 +13,4 @@
|
||||
"types": ["maplibre", "env"],
|
||||
"typeRoots": ["@types"]
|
||||
},
|
||||
"include": ["./src/**/*"]
|
||||
}
|
||||
}
|
||||
|
||||
5
web/lib/tsconfig.sync.json
Normal file
5
web/lib/tsconfig.sync.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"extends": "./tsconfig",
|
||||
"include": ["./src/**/*"],
|
||||
"exclude": ["./src/unsync/*"]
|
||||
}
|
||||
5
web/lib/tsconfig.unsync.json
Normal file
5
web/lib/tsconfig.unsync.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"extends": "./tsconfig",
|
||||
"include": ["./src/**/*"],
|
||||
"exclude": ["./src/sync/*"]
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user