From b9702ea285f8bbc625b3fc64064806d79c9f19af Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Fri, 6 Nov 2020 23:51:10 +0900 Subject: [PATCH] Remove wabt dependency (#156) * Use WasmTransformer.stripCustomSections * Remove wabt dependency --- Brewfile | 1 - Package.resolved | 4 ++-- Package.swift | 2 +- Sources/carton-release/Formula.swift | 1 - Sources/carton/Commands/Bundle.swift | 12 ++++++++++-- install_ubuntu_deps.sh | 4 ---- 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Brewfile b/Brewfile index bedd2a17..b42467a9 100644 --- a/Brewfile +++ b/Brewfile @@ -2,5 +2,4 @@ brew "pre-commit" brew "swiftformat" brew "swiftlint" brew "binaryen" -brew "wabt" brew "wasmer" diff --git a/Package.resolved b/Package.resolved index 92aa6d36..565f0db3 100644 --- a/Package.resolved +++ b/Package.resolved @@ -168,8 +168,8 @@ "repositoryURL": "https://github.com/swiftwasm/WasmTransformer", "state": { "branch": null, - "revision": "c7cb17309372e57c9f75f7abd5c7323d667eaddc", - "version": "0.0.1" + "revision": "74bd6559322b43390eb6da5a134f5af7f117bd01", + "version": "0.0.2" } }, { diff --git a/Package.swift b/Package.swift index a6ffffd6..c677a394 100644 --- a/Package.swift +++ b/Package.swift @@ -26,7 +26,7 @@ let package = Package( .package(url: "https://github.com/vapor/vapor.git", from: "4.29.3"), .package(url: "https://github.com/apple/swift-crypto.git", from: "1.1.0"), .package(url: "https://github.com/JohnSundell/Splash.git", from: "0.14.0"), - .package(url: "https://github.com/swiftwasm/WasmTransformer", .upToNextMinor(from: "0.0.1")), + .package(url: "https://github.com/swiftwasm/WasmTransformer", .upToNextMinor(from: "0.0.2")), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module diff --git a/Sources/carton-release/Formula.swift b/Sources/carton-release/Formula.swift index db4a167d..d2e48a6e 100644 --- a/Sources/carton-release/Formula.swift +++ b/Sources/carton-release/Formula.swift @@ -46,7 +46,6 @@ struct Formula: ParsableCommand { depends_on :xcode => "11.4" depends_on "wasmer" depends_on "binaryen" - depends_on "wabt" stable do version "\#(version)" diff --git a/Sources/carton/Commands/Bundle.swift b/Sources/carton/Commands/Bundle.swift index 7b584b82..0a7fbc3d 100644 --- a/Sources/carton/Commands/Bundle.swift +++ b/Sources/carton/Commands/Bundle.swift @@ -17,6 +17,7 @@ import CartonHelpers import Crypto import SwiftToolchain import TSCBasic +import WasmTransformer private let dependency = Dependency( fileName: "bundle.js", @@ -57,7 +58,8 @@ struct Bundle: ParsableCommand { newline: true ) - try ProcessRunner(["wasm-strip", mainWasmPath.pathString], terminal).waitUntilFinished() + try strip(mainWasmPath) + try terminal.logLookup( "After applying `wasm-strip` the main binary size is ", localFileSystem.humanReadableFileSize(mainWasmPath), @@ -73,7 +75,7 @@ struct Bundle: ParsableCommand { terminal ).waitUntilFinished() try terminal.logLookup( - "After applying `wasm-opt` the main binary size is ", + "After stripping debug info the main binary size is ", localFileSystem.humanReadableFileSize(optimizedPath), newline: true ) @@ -89,6 +91,12 @@ struct Bundle: ParsableCommand { terminal.write("Bundle generation finished successfully\n", inColor: .green, bold: true) } + func strip(_ wasmPath: AbsolutePath) throws { + let binary = try localFileSystem.readFileContents(wasmPath) + let strippedBinary = try stripCustomSections(binary.contents) + try localFileSystem.writeFileContents(wasmPath, bytes: .init(strippedBinary)) + } + func copyToBundle( terminal: InteractiveWriter, optimizedPath: AbsolutePath, diff --git a/install_ubuntu_deps.sh b/install_ubuntu_deps.sh index 147d2e98..6535fa03 100755 --- a/install_ubuntu_deps.sh +++ b/install_ubuntu_deps.sh @@ -2,10 +2,6 @@ set -ex -curl -L -v -o wabt.tar.gz https://github.com/WebAssembly/wabt/releases/download/1.0.19/wabt-1.0.19-ubuntu.tar.gz -tar xzvf wabt.tar.gz -cp wabt-1.0.19/bin/* /usr/local/bin - curl -L -v -o binaryen.tar.gz https://github.com/WebAssembly/binaryen/releases/download/version_97/binaryen-version_97-x86_64-linux.tar.gz tar xzvf binaryen.tar.gz cp binaryen-version_97/bin/* /usr/local/bin