Skip to content

Commit

Permalink
ci: rust toolchain, strip symbols only for wasm2js
Browse files Browse the repository at this point in the history
Various CI failures were happening but went unnoticed because CI wasn't
getting triggered due to cargo.toml not being in CI paths
  • Loading branch information
joe-p committed Mar 8, 2025
1 parent f2b4e86 commit de6b667
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 25 deletions.
17 changes: 12 additions & 5 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,16 @@ jobs:
runner: macos-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.82.0
targets: ${{ matrix.target.name }}
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: "pip" # caching pip dependencies

- name: pip install
- name: pip install
run: |
cd packages/python/${{ env.CRATE }}
pip install ".[dev]"
Expand Down Expand Up @@ -121,7 +122,7 @@ jobs:
- name: Install Rustup
env:
RUN: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-host ${{ env.TARGET }}
RUN: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-host ${{ env.TARGET }} --default-toolchain=1.82.0
run: docker exec build-container bash -c "$RUN"

- name: rustup target add
Expand All @@ -131,7 +132,7 @@ jobs:

- name: Install pip-tools
env:
RUN: python${{ env.PYTHON_VERSION }} -m pip install pip-tools
RUN: python${{ env.PYTHON_VERSION }} -m pip install pip-tools
run: docker exec build-container bash -c "$RUN"

- name: Install dependencies
Expand All @@ -147,14 +148,20 @@ jobs:
env:
RUN: |
cd /workspace/packages/python/${{ env.CRATE }}
python${{ env.PYTHON_VERSION }} -m maturin build --release --target ${{ env.TARGET }} --compatibility ${{ env.MANYLINUX }}
python${{ env.PYTHON_VERSION }} -m maturin build --release --target ${{ env.TARGET }} --compatibility ${{ env.MANYLINUX }} --features ffi_uniffi
run: docker exec build-container bash -c "$RUN"

- name: pip install wheel
env:
RUN: python${{ env.PYTHON_VERSION }} -m pip install /workspace/target/wheels/*.whl
run: docker exec build-container bash -c "$RUN"

- name: Debug module contents
env:
RUN: |
python${{ env.PYTHON_VERSION }} -c "import algo_models; print('Available attributes:', dir(algo_models))"
run: docker exec build-container bash -c "$RUN"

- name: pytest
env:
RUN: |
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/swift_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ jobs:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.82.0
targets: aarch64-apple-ios, x86_64-apple-ios, aarch64-apple-ios-sim, x86_64-apple-ios, aarch64-apple-ios-macabi, x86_64-apple-ios-macabi, aarch64-apple-darwin, x86_64-apple-darwin
- uses: oven-sh/setup-bun@v2
with:
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/typescript_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.82.0
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
Expand Down
7 changes: 0 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,3 @@ members = [
"crates/ffi_macros",
"crates/uniffi-bindgen",
]


[profile.release]
# Need for WASM due to Rust 1.82+ using LLVM with reference-types enabled by default,
# which makes the WASM binary incompatible with wasm2js
# See https://github.com/WebAssembly/binaryen/issues/7358
strip = "symbols"
7 changes: 6 additions & 1 deletion scripts/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@ export function toPascalCase(string: string): string {
.join("");
}

export function run(command: string, cwd: string | null = null): Promise<void> {
export function run(
command: string,
cwd: string | null = null,
env: Record<string, string> = {},
): Promise<void> {
return new Promise<void>((resolvePromise) => {
console.log(`Running '${command}'`);

const args = command.split(" ");
const subProcess = spawn(args[0], args.slice(1), {
cwd: cwd || resolve(__dirname, "../../"),
stdio: ["ignore", "pipe", "pipe"],
env: { ...process.env, ...env },
});

if (subProcess.stdout) {
Expand Down
9 changes: 3 additions & 6 deletions scripts/build/languages/swift.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@ export async function buildSwift(crate: string) {

const allTargets = [...Object.values(fatTargets).flat(), ...targets];

await Promise.all(
allTargets.map(async (target) => {
await run(`rustup target add ${target}`);
cargoBuildCmd += ` --target ${target}`;
}),
);
allTargets.map((target) => {
cargoBuildCmd += ` --target ${target}`;
});

await run(cargoBuildCmd);

Expand Down
11 changes: 7 additions & 4 deletions scripts/build/languages/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ async function wasmPack(
target: "web" | "nodejs" | "bundler",
cwd: string,
) {
await run(
`npx wasm-pack build --out-dir ../../packages/typescript/algo_models/pkg --mode normal --release --target ${target} ../../../crates/${crate}_ffi --no-default-features --features ffi_wasm`,
cwd,
);
const cmd = `npx wasm-pack build --out-dir ../../packages/typescript/algo_models/pkg --mode normal --release --target ${target} ../../../crates/${crate}_ffi --no-default-features --features ffi_wasm`;

await run(cmd, cwd, {
// Needed due to Rust 1.82+ using LLVM with reference-types enabled by default, which makes the WASM binary incompatible with wasm2js
// See https://github.com/WebAssembly/binaryen/issues/7358
RUSTFLAGS: "-C strip=symbols",
});
}

async function build(
Expand Down

0 comments on commit de6b667

Please sign in to comment.