Skip to content

Commit

Permalink
Export to zip files
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Oct 31, 2024
1 parent 02a14b9 commit 11531cb
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 32 deletions.
17 changes: 11 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,22 @@ jobs:
with:
python-version: '3.10'

- name: Use ccache
uses: hendrikmuhs/[email protected]
with:
key: 20241030-${{ matrix.os }}

- name: Bootstrap
run: npx zx bootstrap.mjs --verbose

- name: Build
run: npx zx build.mjs --target-arch ${{ matrix.arch }}

- name: Export
run: npx zx export.mjs

- name: Upload
uses: actions/upload-artifact@v4
with:
name: executorch-${{ matrix.os }}-${{ matrix.arch }}
path: executorch-${{ matrix.os }}-${{ matrix.arch }}-*.zip
retention-days: 1

release:
if: startsWith(github.ref, 'refs/tags/')
needs: [build]
Expand All @@ -60,4 +65,4 @@ jobs:
draft: true
name: ExecuTorch ${{ github.ref_name }}
body: '## Changelog'
files: '*.gz'
files: '*.zip'
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
*.swp
*.zip

/dist
/out
2 changes: 1 addition & 1 deletion bootstrap.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import {python} from './common.mjs';
await $`git submodule sync --recursive`
await $`git submodule update --init --recursive`

await $({cwd: 'executorch'})`${await python()} install_requirements.py`
await $({cwd: 'executorch'})`${python} install_requirements.py`
34 changes: 16 additions & 18 deletions build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {python, torchPath} from './common.mjs';

const flags = [
`CMAKE_PREFIX_PATH=${await torchPath()}`,
`PYTHON_EXECUTABLE=${await python()}`,
`PYTHON_EXECUTABLE=${python}`,
`FLATC_EXECUTABLE=${await which('flatc')}`,
'EXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON',
'EXECUTORCH_BUILD_EXTENSION_MODULE=ON',
Expand All @@ -14,46 +14,44 @@ const flags = [
'EXECUTORCH_BUILD_XNNPACK=ON',
]

const targetArch = argv['target-arch'] || process.arch
const targetOs = argv['target-os'] || {
darwin: 'mac',
linux: 'linux',
win32: 'win',
}[process.platform]

if (process.platform == 'darwin') {
flags.push('CMAKE_TOOLCHAIN_FILE=third-party/ios-cmake/ios.toolchain.cmake',
'DEPLOYMENT_TARGET=10.15',
'EXECUTORCH_BUILD_COREML=ON',
'EXECUTORCH_BUILD_MPS=ON')
const targetArch = argv['target-arch'] || process.arch
if (targetArch == 'arm64')
flags.push('PLATFORM=MAC_ARM64')
else if (targetArch == 'x64')
flags.push('PLATFORM=MAC')
else
throw new Error(`Unsupport target arch ${targetArch} on macOS`)
} else {
if (targetArch != process.arch)
throw new Error('Cross-compilation is not supported except for macOS')
}

// Use ccache when available.
try {
flags.push(`CMAKE_CXX_COMPILER_LAUNCHER=${await which('ccache')}`)
} catch {}

// Use clang when possible.
try {
process.env.CC = await which('clang')
process.env.CXX = await which('clang++')
} catch {}

const outDir = 'out'
// Regenerate project if repo or build args args updated.
const stamp = `${outDir}/.initalized`
const buildArgs = await captureBuildArgs()
if (!fs.existsSync(stamp) || fs.readFileSync(stamp).toString() != buildArgs) {
const outDir = 'out'
const stamp = [ targetArch, targetOs, await $`git submodule`, ...flags ].join('\n')
const stampFile = `${outDir}/.stamp`
if (!fs.existsSync(stampFile) || fs.readFileSync(stampFile).toString() != stamp) {
fs.emptyDirSync(outDir)
await $`cmake executorch -B ${outDir} ${flags.map(f => '-D' + f)}`
fs.writeFileSync(stamp, buildArgs)
fs.writeFileSync(stampFile, stamp)
}

// Run building.
await $`cmake --build ${outDir} --config Release -j`

// Return a text used for identifying whether we should clean out dir.
async function captureBuildArgs() {
const text = await $`git submodule`
return text + flags.join('\n')
}
13 changes: 6 additions & 7 deletions common.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
$.verbose = true

export async function python() {
try {
return await which('python3')
} catch {
return await which('python')
}
export let python
try {
python = await which('python3')
} catch {
python = await which('python')
}

export async function torchPath() {
const r = await $`${await python()} -c 'import torch as _; print(_.__path__[0])'`
const r = await $`${python} -c 'import torch as _; print(_.__path__[0])'`
return r.stdout.trim()
}
25 changes: 25 additions & 0 deletions export.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env zx

import {python} from './common.mjs';

await fs.emptyDir('dist')

// Copy headers.
const headers = await glob([
'executorch/extension/data_loader/**/*.h',
'executorch/extension/module/**/*.h',
'executorch/extension/tensor/**/*.h',
'executorch/runtime/**/*.h',
'executorch/schema/**/*.h',
])
await Promise.all(headers.map(h => fs.copy(h, `dist/include/${h}`)))

// Copy static libs.
const libs = await glob('out/**/*.a')
await Promise.all(libs.map(l => fs.copy(l, `dist/libs/${path.basename(l)}`)))

// Zip files.
const [ targetArch, targetOs ] = String(await fs.readFile('out/.stamp')).split('\n')
const name = `executorch-${targetOs}-${targetArch}-full`
await $`${python} -c "import shutil; shutil.make_archive('${name}', 'zip', 'dist')"`
await fs.remove('dist')

0 comments on commit 11531cb

Please sign in to comment.