From f4ff3fc55c604e615bdebc4e5efd37d3be23ba9a Mon Sep 17 00:00:00 2001 From: Thomas Horrobin Date: Mon, 15 Oct 2018 19:12:24 +0100 Subject: [PATCH 01/30] added basic wasm for development mode --- packages/react-scripts/package.json | 2 ++ packages/react-scripts/template/Cargo.toml | 10 ++++++++++ packages/react-scripts/template/gitignore | 3 +++ packages/react-scripts/template/src/App.js | 8 ++++++++ packages/react-scripts/template/src/lib.rs | 4 ++++ 5 files changed, 27 insertions(+) create mode 100644 packages/react-scripts/template/Cargo.toml create mode 100644 packages/react-scripts/template/src/lib.rs diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index 93e4d4d2d18..cc8a81cedcf 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -63,10 +63,12 @@ "react-app-polyfill": "^0.2.1", "react-dev-utils": "^7.0.3", "resolve": "1.10.0", + "rust-native-wasm-loader": "^0.8.1", "sass-loader": "7.1.0", "style-loader": "0.23.1", "terser-webpack-plugin": "1.2.2", "url-loader": "1.1.2", + "wasm-loader": "^1.3.0", "webpack": "4.28.3", "webpack-dev-server": "3.1.14", "webpack-manifest-plugin": "2.0.4", diff --git a/packages/react-scripts/template/Cargo.toml b/packages/react-scripts/template/Cargo.toml new file mode 100644 index 00000000000..d4a4f31948c --- /dev/null +++ b/packages/react-scripts/template/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "add" +version = "0.1.0" +authors = ["Thomas Horrobin "] +edition = "2018" + +[lib] +crate-type = ["cdylib"] + +[dependencies] diff --git a/packages/react-scripts/template/gitignore b/packages/react-scripts/template/gitignore index 4d29575de80..404580abbd1 100644 --- a/packages/react-scripts/template/gitignore +++ b/packages/react-scripts/template/gitignore @@ -21,3 +21,6 @@ npm-debug.log* yarn-debug.log* yarn-error.log* + +/target +**/*.rs.bk diff --git a/packages/react-scripts/template/src/App.js b/packages/react-scripts/template/src/App.js index 7e261ca47e6..4cd202560d6 100644 --- a/packages/react-scripts/template/src/App.js +++ b/packages/react-scripts/template/src/App.js @@ -1,8 +1,16 @@ import React, { Component } from 'react'; import logo from './logo.svg'; import './App.css'; +import loadAdd from './lib.rs'; class App extends Component { + constructor() { + super(); + loadAdd().then(result => { + const addtwo = result.instance.exports['addtwo']; + alert(`return value was ${addtwo(2)}`); + }); + } render() { return (
diff --git a/packages/react-scripts/template/src/lib.rs b/packages/react-scripts/template/src/lib.rs new file mode 100644 index 00000000000..9a46f425601 --- /dev/null +++ b/packages/react-scripts/template/src/lib.rs @@ -0,0 +1,4 @@ +#[no_mangle] +pub fn addtwo(a: i32) -> i32 { + a + 2 +} From 1a262be153583f5ce1a70740451c2773d871eb88 Mon Sep 17 00:00:00 2001 From: Thomas Horrobin Date: Mon, 15 Oct 2018 22:06:05 +0100 Subject: [PATCH 02/30] added prod and dev build targets --- packages/react-scripts/scripts/build.js | 6 +++-- .../scripts/utils/rustCompiler.js | 8 ++++++ packages/react-scripts/template/src/App.js | 25 +++++++++++++++---- 3 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 packages/react-scripts/scripts/utils/rustCompiler.js diff --git a/packages/react-scripts/scripts/build.js b/packages/react-scripts/scripts/build.js index 8cd1ad77ee5..ff90b498975 100644 --- a/packages/react-scripts/scripts/build.js +++ b/packages/react-scripts/scripts/build.js @@ -64,10 +64,12 @@ if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) { const argv = process.argv.slice(2); const writeStatsJson = argv.indexOf('--stats') !== -1; -// Generate configuration const config = configFactory('production'); -// We require that you explicitly set browsers and do not fall back to +const compileRust = require('./utils/rustCompiler'); +compileRust(); + +// We require that you explictly set browsers and do not fall back to // browserslist defaults. const { checkBrowsers } = require('react-dev-utils/browsersHelper'); checkBrowsers(paths.appPath, isInteractive) diff --git a/packages/react-scripts/scripts/utils/rustCompiler.js b/packages/react-scripts/scripts/utils/rustCompiler.js new file mode 100644 index 00000000000..268412d1fab --- /dev/null +++ b/packages/react-scripts/scripts/utils/rustCompiler.js @@ -0,0 +1,8 @@ +const execSync = require('child_process').execSync; + +module.exports = () => { + execSync( + 'rustc +nightly --target wasm32-unknown-unknown -O --crate-type=cdylib src/lib.rs -o public/app.big.wasm && wasm-gc public/app.big.wasm public/app.wasm' + // 'rustc +nightly --target wasm32-unknown-unknown -O --crate-type=cdylib src/lib.rs -o public/app.big.wasm && wasm-gc public/app.big.wasm public/app.wasm && rm public/app.big.wasm' + ); +}; diff --git a/packages/react-scripts/template/src/App.js b/packages/react-scripts/template/src/App.js index 4cd202560d6..609f2dea298 100644 --- a/packages/react-scripts/template/src/App.js +++ b/packages/react-scripts/template/src/App.js @@ -1,15 +1,30 @@ import React, { Component } from 'react'; import logo from './logo.svg'; import './App.css'; -import loadAdd from './lib.rs'; class App extends Component { constructor() { super(); - loadAdd().then(result => { - const addtwo = result.instance.exports['addtwo']; - alert(`return value was ${addtwo(2)}`); - }); + switch (process.env.NODE_ENV) { + case 'production': + fetch('app.wasm') + .then(response => response.arrayBuffer()) + .then(bytes => WebAssembly.instantiate(bytes, {})) + .then(result => { + const addtwo = result.instance.exports['addtwo']; + alert(`return value was ${addtwo(3)}`); + }); + break; + case 'development': + import loadAdd from './lib.rs'; + loadAdd().then(result => { + const addtwo = result.instance.exports['addtwo']; + alert(`return value was ${addtwo(2)}`); + }); + break; + default: + break; + } } render() { return ( From eae1ddb198f110097ee861e22ee571b262cf0bb7 Mon Sep 17 00:00:00 2001 From: Thomas Horrobin Date: Tue, 16 Oct 2018 17:29:30 +0100 Subject: [PATCH 03/30] added package.json for scripts file --- packages/react-scripts/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index cc8a81cedcf..84b52c7a931 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -8,7 +8,7 @@ "node": ">=6" }, "bugs": { - "url": "https://github.com/facebook/create-react-app/issues" + "url": "https://github.com/thomashorrobin/create-react-app-rust/issues" }, "files": [ "bin", From 14ef93312d95ee7deca225b9bedea43aa1e51c43 Mon Sep 17 00:00:00 2001 From: Thomas Horrobin Date: Tue, 16 Oct 2018 18:21:05 +0100 Subject: [PATCH 04/30] fixed importing bug --- packages/react-scripts/template/src/App.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-scripts/template/src/App.js b/packages/react-scripts/template/src/App.js index 609f2dea298..322a7690644 100644 --- a/packages/react-scripts/template/src/App.js +++ b/packages/react-scripts/template/src/App.js @@ -1,6 +1,7 @@ import React, { Component } from 'react'; import logo from './logo.svg'; import './App.css'; +import loadAdd from './lib.rs'; class App extends Component { constructor() { @@ -16,7 +17,6 @@ class App extends Component { }); break; case 'development': - import loadAdd from './lib.rs'; loadAdd().then(result => { const addtwo = result.instance.exports['addtwo']; alert(`return value was ${addtwo(2)}`); From 008c043df1646038ada2eda08cb2ac294e8ec0e9 Mon Sep 17 00:00:00 2001 From: Thomas Horrobin Date: Wed, 17 Oct 2018 13:22:04 +0100 Subject: [PATCH 05/30] added err handling for rm cmd (Windows issue) --- .../react-scripts/scripts/utils/rustCompiler.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/react-scripts/scripts/utils/rustCompiler.js b/packages/react-scripts/scripts/utils/rustCompiler.js index 268412d1fab..9ba07775217 100644 --- a/packages/react-scripts/scripts/utils/rustCompiler.js +++ b/packages/react-scripts/scripts/utils/rustCompiler.js @@ -1,8 +1,13 @@ const execSync = require('child_process').execSync; module.exports = () => { - execSync( - 'rustc +nightly --target wasm32-unknown-unknown -O --crate-type=cdylib src/lib.rs -o public/app.big.wasm && wasm-gc public/app.big.wasm public/app.wasm' - // 'rustc +nightly --target wasm32-unknown-unknown -O --crate-type=cdylib src/lib.rs -o public/app.big.wasm && wasm-gc public/app.big.wasm public/app.wasm && rm public/app.big.wasm' - ); + try { + execSync( + 'rustc +nightly --target wasm32-unknown-unknown -O --crate-type=cdylib src/lib.rs -o public/app.big.wasm && wasm-gc public/app.big.wasm public/app.wasm && rm public/app.big.wasm' + ); + } catch (error) { + execSync( + 'rustc +nightly --target wasm32-unknown-unknown -O --crate-type=cdylib src/lib.rs -o public/app.big.wasm && wasm-gc public/app.big.wasm public/app.wasm' + ); + } }; From 104d551d42c1dd00a5ecf6cc5dc9d1ed3bd87d70 Mon Sep 17 00:00:00 2001 From: Thomas Horrobin Date: Wed, 17 Oct 2018 18:44:36 +0100 Subject: [PATCH 06/30] added comments and PowerShell specific cmd --- packages/react-scripts/scripts/utils/rustCompiler.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/react-scripts/scripts/utils/rustCompiler.js b/packages/react-scripts/scripts/utils/rustCompiler.js index 9ba07775217..272f0ed3708 100644 --- a/packages/react-scripts/scripts/utils/rustCompiler.js +++ b/packages/react-scripts/scripts/utils/rustCompiler.js @@ -1,13 +1,15 @@ const execSync = require('child_process').execSync; module.exports = () => { + // first build app.big.wasm and then optimize to app.wasm with wasm-gc try { execSync( 'rustc +nightly --target wasm32-unknown-unknown -O --crate-type=cdylib src/lib.rs -o public/app.big.wasm && wasm-gc public/app.big.wasm public/app.wasm && rm public/app.big.wasm' ); } catch (error) { + // on Windoze sometimes 'rm' is not reliable. if it fails try with this execSync( - 'rustc +nightly --target wasm32-unknown-unknown -O --crate-type=cdylib src/lib.rs -o public/app.big.wasm && wasm-gc public/app.big.wasm public/app.wasm' + 'Remove-File ./public/app.big.wasm' ); } }; From 6cf1fc0178f8d8a2325cd41dd7bf61a20a3f9d0a Mon Sep 17 00:00:00 2001 From: Thomas Horrobin Date: Wed, 17 Oct 2018 18:50:44 +0100 Subject: [PATCH 07/30] renamed file --- packages/react-scripts/scripts/build.js | 2 +- .../scripts/utils/{rustCompiler.js => rustUtils.js} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename packages/react-scripts/scripts/utils/{rustCompiler.js => rustUtils.js} (100%) diff --git a/packages/react-scripts/scripts/build.js b/packages/react-scripts/scripts/build.js index ff90b498975..023fd48aaa7 100644 --- a/packages/react-scripts/scripts/build.js +++ b/packages/react-scripts/scripts/build.js @@ -66,7 +66,7 @@ const writeStatsJson = argv.indexOf('--stats') !== -1; const config = configFactory('production'); -const compileRust = require('./utils/rustCompiler'); +const compileRust = require('./utils/rustUtils'); compileRust(); // We require that you explictly set browsers and do not fall back to diff --git a/packages/react-scripts/scripts/utils/rustCompiler.js b/packages/react-scripts/scripts/utils/rustUtils.js similarity index 100% rename from packages/react-scripts/scripts/utils/rustCompiler.js rename to packages/react-scripts/scripts/utils/rustUtils.js From 253c0300341e6aabc067f92b024b610a1abdae64 Mon Sep 17 00:00:00 2001 From: Thomas Horrobin Date: Wed, 17 Oct 2018 21:00:57 +0100 Subject: [PATCH 08/30] restructured rustUtils --- packages/react-scripts/scripts/build.js | 4 +-- .../react-scripts/scripts/utils/rustUtils.js | 26 ++++++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/react-scripts/scripts/build.js b/packages/react-scripts/scripts/build.js index 023fd48aaa7..0b551ced37a 100644 --- a/packages/react-scripts/scripts/build.js +++ b/packages/react-scripts/scripts/build.js @@ -66,8 +66,8 @@ const writeStatsJson = argv.indexOf('--stats') !== -1; const config = configFactory('production'); -const compileRust = require('./utils/rustUtils'); -compileRust(); +const rustUtils = require('./utils/rustUtils'); +rustUtils.build(); // We require that you explictly set browsers and do not fall back to // browserslist defaults. diff --git a/packages/react-scripts/scripts/utils/rustUtils.js b/packages/react-scripts/scripts/utils/rustUtils.js index 272f0ed3708..0b004532649 100644 --- a/packages/react-scripts/scripts/utils/rustUtils.js +++ b/packages/react-scripts/scripts/utils/rustUtils.js @@ -1,15 +1,17 @@ const execSync = require('child_process').execSync; -module.exports = () => { - // first build app.big.wasm and then optimize to app.wasm with wasm-gc - try { - execSync( - 'rustc +nightly --target wasm32-unknown-unknown -O --crate-type=cdylib src/lib.rs -o public/app.big.wasm && wasm-gc public/app.big.wasm public/app.wasm && rm public/app.big.wasm' - ); - } catch (error) { - // on Windoze sometimes 'rm' is not reliable. if it fails try with this - execSync( - 'Remove-File ./public/app.big.wasm' - ); +module.exports = { + build: () => { + // first build app.big.wasm and then optimize to app.wasm with wasm-gc + try { + execSync( + 'rustc +nightly --target wasm32-unknown-unknown -O --crate-type=cdylib src/lib.rs -o public/app.big.wasm && wasm-gc public/app.big.wasm public/app.wasm && rm public/app.big.wasm' + ); + } catch (error) { + // on Windoze sometimes 'rm' is not reliable. if it fails try with this + execSync( + 'Remove-File ./public/app.big.wasm' + ); + } } -}; +} From c9889e25c4a5aa6f7bdeedb17e720e0b5c38cb3c Mon Sep 17 00:00:00 2001 From: Thomas Horrobin Date: Wed, 17 Oct 2018 21:33:46 +0100 Subject: [PATCH 09/30] added rust setup code --- packages/react-scripts/scripts/init.js | 8 ++++++++ .../react-scripts/scripts/utils/rustUtils.js | 16 +++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/react-scripts/scripts/init.js b/packages/react-scripts/scripts/init.js index 9b473ab3d95..b4257c28e62 100644 --- a/packages/react-scripts/scripts/init.js +++ b/packages/react-scripts/scripts/init.js @@ -204,6 +204,14 @@ module.exports = function( console.log('Initialized a git repository.'); } + const rustUtils = require('./utils/rustUtils'); + + if (!rustUtils.isRustInstalled()) { + rustUtils.installRust(); + } + + rustUtils.installRustWebAssemblyTools(); + // Display the most elegant way to cd. // This needs to handle an undefined originalDirectory for // backward compatibility with old global-cli's. diff --git a/packages/react-scripts/scripts/utils/rustUtils.js b/packages/react-scripts/scripts/utils/rustUtils.js index 0b004532649..a4a9d133973 100644 --- a/packages/react-scripts/scripts/utils/rustUtils.js +++ b/packages/react-scripts/scripts/utils/rustUtils.js @@ -13,5 +13,19 @@ module.exports = { 'Remove-File ./public/app.big.wasm' ); } - } + }, + isRustInstalled: () => { + try { + execSync('rustup -v'); + return true; + } catch (error) { + return false; + } + }, + installRustWebAssemblyTools: () => { + execSync('rustup default nightly && rustup update nightly && rustup target add wasm32-unknown-unknown --toolchain nightly && cargo install --force --git https://github.com/alexcrichton/wasm-gc'); + }, + installRust: () => { + execSync('curl https://sh.rustup.rs -sSf | sh'); + }, } From 68a82807d811d113fdf244032782d9d5c0c09ab7 Mon Sep 17 00:00:00 2001 From: Thomas Horrobin Date: Thu, 18 Oct 2018 15:18:08 +0100 Subject: [PATCH 10/30] removed code that would install rustup --- packages/react-scripts/scripts/init.js | 5 ++++- packages/react-scripts/scripts/utils/rustUtils.js | 15 ++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/react-scripts/scripts/init.js b/packages/react-scripts/scripts/init.js index b4257c28e62..42c19fbcd5f 100644 --- a/packages/react-scripts/scripts/init.js +++ b/packages/react-scripts/scripts/init.js @@ -207,7 +207,10 @@ module.exports = function( const rustUtils = require('./utils/rustUtils'); if (!rustUtils.isRustInstalled()) { - rustUtils.installRust(); + console.error( + 'please install rust https://www.rust-lang.org/en-US/install.html' + ); + return; } rustUtils.installRustWebAssemblyTools(); diff --git a/packages/react-scripts/scripts/utils/rustUtils.js b/packages/react-scripts/scripts/utils/rustUtils.js index a4a9d133973..2565b96eb77 100644 --- a/packages/react-scripts/scripts/utils/rustUtils.js +++ b/packages/react-scripts/scripts/utils/rustUtils.js @@ -1,6 +1,6 @@ const execSync = require('child_process').execSync; -module.exports = { +module.exports = { build: () => { // first build app.big.wasm and then optimize to app.wasm with wasm-gc try { @@ -9,9 +9,7 @@ module.exports = { ); } catch (error) { // on Windoze sometimes 'rm' is not reliable. if it fails try with this - execSync( - 'Remove-File ./public/app.big.wasm' - ); + execSync('Remove-File ./public/app.big.wasm'); } }, isRustInstalled: () => { @@ -23,9 +21,8 @@ module.exports = { } }, installRustWebAssemblyTools: () => { - execSync('rustup default nightly && rustup update nightly && rustup target add wasm32-unknown-unknown --toolchain nightly && cargo install --force --git https://github.com/alexcrichton/wasm-gc'); - }, - installRust: () => { - execSync('curl https://sh.rustup.rs -sSf | sh'); + execSync( + 'rustup default nightly && rustup update nightly && rustup target add wasm32-unknown-unknown --toolchain nightly && cargo install --force --git https://github.com/alexcrichton/wasm-gc' + ); }, -} +}; From 3d9cbd68fc0412af0d92e047037def769c8a2b41 Mon Sep 17 00:00:00 2001 From: Thomas Horrobin Date: Thu, 18 Oct 2018 19:12:02 +0100 Subject: [PATCH 11/30] improved errors --- packages/react-scripts/scripts/init.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/react-scripts/scripts/init.js b/packages/react-scripts/scripts/init.js index 42c19fbcd5f..055cf326d91 100644 --- a/packages/react-scripts/scripts/init.js +++ b/packages/react-scripts/scripts/init.js @@ -207,8 +207,11 @@ module.exports = function( const rustUtils = require('./utils/rustUtils'); if (!rustUtils.isRustInstalled()) { - console.error( - 'please install rust https://www.rust-lang.org/en-US/install.html' + console.log( + chalk.bold.red('rust not installed') + ); + console.log( + 'install rust from here https://www.rust-lang.org/en-US/install.html' ); return; } From 4975e02fb3099c01f072a0d63b7cda828b18b4ce Mon Sep 17 00:00:00 2001 From: Thomas Horrobin Date: Fri, 19 Oct 2018 11:25:41 +0100 Subject: [PATCH 12/30] renamed lib.rs to App.rs --- packages/react-scripts/scripts/utils/rustUtils.js | 2 +- packages/react-scripts/template/src/App.js | 2 +- packages/react-scripts/template/src/{lib.rs => App.rs} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename packages/react-scripts/template/src/{lib.rs => App.rs} (100%) diff --git a/packages/react-scripts/scripts/utils/rustUtils.js b/packages/react-scripts/scripts/utils/rustUtils.js index 2565b96eb77..86147ff3624 100644 --- a/packages/react-scripts/scripts/utils/rustUtils.js +++ b/packages/react-scripts/scripts/utils/rustUtils.js @@ -5,7 +5,7 @@ module.exports = { // first build app.big.wasm and then optimize to app.wasm with wasm-gc try { execSync( - 'rustc +nightly --target wasm32-unknown-unknown -O --crate-type=cdylib src/lib.rs -o public/app.big.wasm && wasm-gc public/app.big.wasm public/app.wasm && rm public/app.big.wasm' + 'rustc +nightly --target wasm32-unknown-unknown -O --crate-type=cdylib src/App.rs -o public/app.big.wasm && wasm-gc public/app.big.wasm public/app.wasm && rm public/app.big.wasm' ); } catch (error) { // on Windoze sometimes 'rm' is not reliable. if it fails try with this diff --git a/packages/react-scripts/template/src/App.js b/packages/react-scripts/template/src/App.js index 322a7690644..d95bae3bd3e 100644 --- a/packages/react-scripts/template/src/App.js +++ b/packages/react-scripts/template/src/App.js @@ -1,7 +1,7 @@ import React, { Component } from 'react'; import logo from './logo.svg'; import './App.css'; -import loadAdd from './lib.rs'; +import loadAdd from './App.rs'; class App extends Component { constructor() { diff --git a/packages/react-scripts/template/src/lib.rs b/packages/react-scripts/template/src/App.rs similarity index 100% rename from packages/react-scripts/template/src/lib.rs rename to packages/react-scripts/template/src/App.rs From 2e5e9907f6fd4b25ab8181a077bb12e6e5aa6fe3 Mon Sep 17 00:00:00 2001 From: Thomas Horrobin Date: Fri, 19 Oct 2018 13:45:14 +0100 Subject: [PATCH 13/30] changed rust smoke test cmd --- packages/react-scripts/scripts/utils/rustUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-scripts/scripts/utils/rustUtils.js b/packages/react-scripts/scripts/utils/rustUtils.js index 86147ff3624..6ddd64cdf2d 100644 --- a/packages/react-scripts/scripts/utils/rustUtils.js +++ b/packages/react-scripts/scripts/utils/rustUtils.js @@ -14,7 +14,7 @@ module.exports = { }, isRustInstalled: () => { try { - execSync('rustup -v'); + execSync('rustup show'); return true; } catch (error) { return false; From 0eff644c6253dcc47ca79c58f822a4f93e2a755c Mon Sep 17 00:00:00 2001 From: Thomas Horrobin Date: Fri, 19 Oct 2018 14:06:55 +0100 Subject: [PATCH 14/30] removed not working windows specific code --- packages/react-scripts/scripts/utils/rustUtils.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/react-scripts/scripts/utils/rustUtils.js b/packages/react-scripts/scripts/utils/rustUtils.js index 6ddd64cdf2d..1c484c69e97 100644 --- a/packages/react-scripts/scripts/utils/rustUtils.js +++ b/packages/react-scripts/scripts/utils/rustUtils.js @@ -7,10 +7,7 @@ module.exports = { execSync( 'rustc +nightly --target wasm32-unknown-unknown -O --crate-type=cdylib src/App.rs -o public/app.big.wasm && wasm-gc public/app.big.wasm public/app.wasm && rm public/app.big.wasm' ); - } catch (error) { - // on Windoze sometimes 'rm' is not reliable. if it fails try with this - execSync('Remove-File ./public/app.big.wasm'); - } + } catch (error) {} }, isRustInstalled: () => { try { From 3c92562090a09d55fa9756e2c2daad786afb4381 Mon Sep 17 00:00:00 2001 From: Thomas Horrobin Date: Fri, 19 Oct 2018 14:20:41 +0100 Subject: [PATCH 15/30] added fix for brocken rust --- packages/react-scripts/template/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/react-scripts/template/Cargo.toml b/packages/react-scripts/template/Cargo.toml index d4a4f31948c..5e91c518759 100644 --- a/packages/react-scripts/template/Cargo.toml +++ b/packages/react-scripts/template/Cargo.toml @@ -6,5 +6,6 @@ edition = "2018" [lib] crate-type = ["cdylib"] +path = "src/App.rs" [dependencies] From 127003d766498c5b91277c6c152af543e3404e70 Mon Sep 17 00:00:00 2001 From: Thomas Horrobin Date: Fri, 19 Oct 2018 14:28:24 +0100 Subject: [PATCH 16/30] renamed ruction to allighn with hellorust --- packages/react-scripts/template/src/App.js | 8 ++++---- packages/react-scripts/template/src/App.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/react-scripts/template/src/App.js b/packages/react-scripts/template/src/App.js index d95bae3bd3e..f0df9da1d03 100644 --- a/packages/react-scripts/template/src/App.js +++ b/packages/react-scripts/template/src/App.js @@ -12,14 +12,14 @@ class App extends Component { .then(response => response.arrayBuffer()) .then(bytes => WebAssembly.instantiate(bytes, {})) .then(result => { - const addtwo = result.instance.exports['addtwo']; - alert(`return value was ${addtwo(3)}`); + const add_one = result.instance.exports['add_one']; + alert(`return value was ${add_one(3)}`); }); break; case 'development': loadAdd().then(result => { - const addtwo = result.instance.exports['addtwo']; - alert(`return value was ${addtwo(2)}`); + const add_one = result.instance.exports['add_one']; + alert(`return value was ${add_one(2)}`); }); break; default: diff --git a/packages/react-scripts/template/src/App.rs b/packages/react-scripts/template/src/App.rs index 9a46f425601..b3cd5c42148 100644 --- a/packages/react-scripts/template/src/App.rs +++ b/packages/react-scripts/template/src/App.rs @@ -1,4 +1,4 @@ #[no_mangle] -pub fn addtwo(a: i32) -> i32 { - a + 2 +pub extern "C" fn add_one(x: i32) -> i32 { + x + 1 } From 47aad0114d593f5b24221002e97ce149acc51b67 Mon Sep 17 00:00:00 2001 From: Thomas Horrobin Date: Sun, 21 Oct 2018 13:28:47 +0100 Subject: [PATCH 17/30] added better logging --- packages/react-scripts/scripts/init.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/react-scripts/scripts/init.js b/packages/react-scripts/scripts/init.js index 055cf326d91..64fa15c156c 100644 --- a/packages/react-scripts/scripts/init.js +++ b/packages/react-scripts/scripts/init.js @@ -206,7 +206,9 @@ module.exports = function( const rustUtils = require('./utils/rustUtils'); - if (!rustUtils.isRustInstalled()) { + if (rustUtils.isRustInstalled()) { + console.log('rust installed 👍'); + } else { console.log( chalk.bold.red('rust not installed') ); From 4783f1b0ad840bb8621439e29bfeeab391bd0abd Mon Sep 17 00:00:00 2001 From: Thomas Horrobin Date: Sun, 21 Oct 2018 14:11:38 +0100 Subject: [PATCH 18/30] removed wasm-gc --- packages/react-scripts/scripts/utils/rustUtils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react-scripts/scripts/utils/rustUtils.js b/packages/react-scripts/scripts/utils/rustUtils.js index 1c484c69e97..06fd42ab09b 100644 --- a/packages/react-scripts/scripts/utils/rustUtils.js +++ b/packages/react-scripts/scripts/utils/rustUtils.js @@ -5,7 +5,7 @@ module.exports = { // first build app.big.wasm and then optimize to app.wasm with wasm-gc try { execSync( - 'rustc +nightly --target wasm32-unknown-unknown -O --crate-type=cdylib src/App.rs -o public/app.big.wasm && wasm-gc public/app.big.wasm public/app.wasm && rm public/app.big.wasm' + 'rustc +nightly --target wasm32-unknown-unknown -O --crate-type=cdylib src/App.rs -o public/app.wasm' ); } catch (error) {} }, @@ -19,7 +19,7 @@ module.exports = { }, installRustWebAssemblyTools: () => { execSync( - 'rustup default nightly && rustup update nightly && rustup target add wasm32-unknown-unknown --toolchain nightly && cargo install --force --git https://github.com/alexcrichton/wasm-gc' + 'rustup default nightly && rustup update nightly && rustup target add wasm32-unknown-unknown --toolchain nightly' ); }, }; From b3bc2fd7fa2876166972f7918218cd6009719d84 Mon Sep 17 00:00:00 2001 From: Thomas Horrobin Date: Sun, 21 Oct 2018 23:58:15 +0100 Subject: [PATCH 19/30] abstracted wasm loading App.rs --- packages/react-scripts/template/src/App.js | 25 ++++--------------- .../react-scripts/template/src/wasmLoader.js | 17 +++++++++++++ 2 files changed, 22 insertions(+), 20 deletions(-) create mode 100644 packages/react-scripts/template/src/wasmLoader.js diff --git a/packages/react-scripts/template/src/App.js b/packages/react-scripts/template/src/App.js index f0df9da1d03..94d371f6356 100644 --- a/packages/react-scripts/template/src/App.js +++ b/packages/react-scripts/template/src/App.js @@ -1,30 +1,15 @@ import React, { Component } from 'react'; import logo from './logo.svg'; import './App.css'; -import loadAdd from './App.rs'; +import { loadWasm } from "./wasmLoader"; class App extends Component { constructor() { super(); - switch (process.env.NODE_ENV) { - case 'production': - fetch('app.wasm') - .then(response => response.arrayBuffer()) - .then(bytes => WebAssembly.instantiate(bytes, {})) - .then(result => { - const add_one = result.instance.exports['add_one']; - alert(`return value was ${add_one(3)}`); - }); - break; - case 'development': - loadAdd().then(result => { - const add_one = result.instance.exports['add_one']; - alert(`return value was ${add_one(2)}`); - }); - break; - default: - break; - } + loadWasm(result => { + const add_one = result.instance.exports['add_one']; + alert(`return value was ${add_one(3)}`); + }); } render() { return ( diff --git a/packages/react-scripts/template/src/wasmLoader.js b/packages/react-scripts/template/src/wasmLoader.js new file mode 100644 index 00000000000..9b65ced3e5c --- /dev/null +++ b/packages/react-scripts/template/src/wasmLoader.js @@ -0,0 +1,17 @@ +import rustFile from './App.rs'; + +export function loadWasm(handleResultObjectPromise) { + switch (process.env.NODE_ENV) { + case 'production': + fetch('app.wasm') + .then(response => response.arrayBuffer()) + .then(bytes => WebAssembly.instantiate(bytes, {})) + .then(handleResultObjectPromise); + break; + case 'development': + rustFile().then(handleResultObjectPromise); + break; + default: + break; + } +} \ No newline at end of file From 959fca57d6ea84779815501cc447cab022808671 Mon Sep 17 00:00:00 2001 From: Thomas Horrobin Date: Mon, 22 Oct 2018 12:01:56 +0100 Subject: [PATCH 20/30] added stdout and stderr to execSync calls --- packages/react-scripts/scripts/utils/rustUtils.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/react-scripts/scripts/utils/rustUtils.js b/packages/react-scripts/scripts/utils/rustUtils.js index 06fd42ab09b..fa0ff8e0d90 100644 --- a/packages/react-scripts/scripts/utils/rustUtils.js +++ b/packages/react-scripts/scripts/utils/rustUtils.js @@ -5,7 +5,8 @@ module.exports = { // first build app.big.wasm and then optimize to app.wasm with wasm-gc try { execSync( - 'rustc +nightly --target wasm32-unknown-unknown -O --crate-type=cdylib src/App.rs -o public/app.wasm' + 'rustc +nightly --target wasm32-unknown-unknown -O --crate-type=cdylib src/App.rs -o public/app.wasm', + { stdio: 'inherit' } ); } catch (error) {} }, @@ -19,7 +20,8 @@ module.exports = { }, installRustWebAssemblyTools: () => { execSync( - 'rustup default nightly && rustup update nightly && rustup target add wasm32-unknown-unknown --toolchain nightly' + 'rustup default nightly && rustup update nightly && rustup target add wasm32-unknown-unknown --toolchain nightly', + { stdio: 'inherit' } ); }, }; From 7c1f49e689c934a147f14fa4054bee6df307c178 Mon Sep 17 00:00:00 2001 From: Thomas Horrobin Date: Mon, 22 Oct 2018 15:36:01 +0100 Subject: [PATCH 21/30] readded wasm-gc --- packages/react-scripts/scripts/build.js | 8 ++++---- .../react-scripts/scripts/utils/rustUtils.js | 18 +++++++++++++++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/packages/react-scripts/scripts/build.js b/packages/react-scripts/scripts/build.js index 0b551ced37a..d689fdfc261 100644 --- a/packages/react-scripts/scripts/build.js +++ b/packages/react-scripts/scripts/build.js @@ -43,6 +43,7 @@ const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages'); const printHostingInstructions = require('react-dev-utils/printHostingInstructions'); const FileSizeReporter = require('react-dev-utils/FileSizeReporter'); const printBuildError = require('react-dev-utils/printBuildError'); +const rustUtils = require('./utils/rustUtils'); const measureFileSizesBeforeBuild = FileSizeReporter.measureFileSizesBeforeBuild; @@ -66,10 +67,7 @@ const writeStatsJson = argv.indexOf('--stats') !== -1; const config = configFactory('production'); -const rustUtils = require('./utils/rustUtils'); -rustUtils.build(); - -// We require that you explictly set browsers and do not fall back to +// We require that you explicitly set browsers and do not fall back to // browserslist defaults. const { checkBrowsers } = require('react-dev-utils/browsersHelper'); checkBrowsers(paths.appPath, isInteractive) @@ -84,6 +82,8 @@ checkBrowsers(paths.appPath, isInteractive) fs.emptyDirSync(paths.appBuild); // Merge with the public folder copyPublicFolder(); + // compile Rust to wasm + rustUtils.build(); // Start the webpack build return build(previousFileSizes); }) diff --git a/packages/react-scripts/scripts/utils/rustUtils.js b/packages/react-scripts/scripts/utils/rustUtils.js index fa0ff8e0d90..ae6e80a27b3 100644 --- a/packages/react-scripts/scripts/utils/rustUtils.js +++ b/packages/react-scripts/scripts/utils/rustUtils.js @@ -1,14 +1,26 @@ const execSync = require('child_process').execSync; +const chalk = require('chalk'); module.exports = { build: () => { - // first build app.big.wasm and then optimize to app.wasm with wasm-gc try { + // first build app.wasm and then optimize with wasm-gc execSync( - 'rustc +nightly --target wasm32-unknown-unknown -O --crate-type=cdylib src/App.rs -o public/app.wasm', + 'rustc +nightly --target wasm32-unknown-unknown -O --crate-type=cdylib src/App.rs -o build/app.wasm', { stdio: 'inherit' } ); - } catch (error) {} + try { + // check to see if wasm-gc is installed and if not install it + execSync('wasm-gc'); + } catch (err) { + execSync('cargo install wasm-gc', { stdio: 'inherit' }); + } finally { + // think of this like running --gc-sections on the app.wasm file + execSync('wasm-gc build/app.wasm', { stdio: 'inherit' }); + } + } catch (error) { + console.log(chalk.bold.red('error compiling rust')); + } }, isRustInstalled: () => { try { From 59fe7c21a882e64f2a26c58150a26d40d729d2a2 Mon Sep 17 00:00:00 2001 From: Thomas Horrobin Date: Tue, 23 Oct 2018 23:54:56 +0100 Subject: [PATCH 22/30] updated READMEs to give greater guidance to end users --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 75aed91b989..935306c3a56 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,13 @@ If something doesn’t work, please [file an issue](https://github.com/facebook/ ## Quick Overview +If you haven't already you'll need to install Rust and source it into your current context +```sh +curl https://sh.rustup.rs -sSf | sh +source $HOME/.cargo/env +``` + +Then you can run the tool with `npx` ```sh npx create-react-app my-app cd my-app From a8736eee1e382cad6b62f00a11e60290d03090cb Mon Sep 17 00:00:00 2001 From: Thomas Horrobin Date: Wed, 24 Oct 2018 13:02:20 +0100 Subject: [PATCH 23/30] added rust-toolchain --- packages/react-scripts/package.json | 2 +- packages/react-scripts/scripts/utils/rustUtils.js | 2 +- packages/react-scripts/template/rust-toolchain | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 packages/react-scripts/template/rust-toolchain diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index 84b52c7a931..cc8a81cedcf 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -8,7 +8,7 @@ "node": ">=6" }, "bugs": { - "url": "https://github.com/thomashorrobin/create-react-app-rust/issues" + "url": "https://github.com/facebook/create-react-app/issues" }, "files": [ "bin", diff --git a/packages/react-scripts/scripts/utils/rustUtils.js b/packages/react-scripts/scripts/utils/rustUtils.js index ae6e80a27b3..f4b9a754474 100644 --- a/packages/react-scripts/scripts/utils/rustUtils.js +++ b/packages/react-scripts/scripts/utils/rustUtils.js @@ -32,7 +32,7 @@ module.exports = { }, installRustWebAssemblyTools: () => { execSync( - 'rustup default nightly && rustup update nightly && rustup target add wasm32-unknown-unknown --toolchain nightly', + 'rustup target add wasm32-unknown-unknown --toolchain nightly', { stdio: 'inherit' } ); }, diff --git a/packages/react-scripts/template/rust-toolchain b/packages/react-scripts/template/rust-toolchain new file mode 100644 index 00000000000..07ade694b1a --- /dev/null +++ b/packages/react-scripts/template/rust-toolchain @@ -0,0 +1 @@ +nightly \ No newline at end of file From 6b052f8c3fc7249b6025cfd37901cbe3dc8e7f11 Mon Sep 17 00:00:00 2001 From: Thomas Horrobin Date: Wed, 24 Oct 2018 13:15:46 +0100 Subject: [PATCH 24/30] add install for wasm-gc --- .../react-scripts/scripts/utils/rustUtils.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/packages/react-scripts/scripts/utils/rustUtils.js b/packages/react-scripts/scripts/utils/rustUtils.js index f4b9a754474..964d042c107 100644 --- a/packages/react-scripts/scripts/utils/rustUtils.js +++ b/packages/react-scripts/scripts/utils/rustUtils.js @@ -6,18 +6,9 @@ module.exports = { try { // first build app.wasm and then optimize with wasm-gc execSync( - 'rustc +nightly --target wasm32-unknown-unknown -O --crate-type=cdylib src/App.rs -o build/app.wasm', + 'rustc +nightly --target wasm32-unknown-unknown -O --crate-type=cdylib src/App.rs -o build/app.wasm && wasm-gc build/app.wasm', { stdio: 'inherit' } ); - try { - // check to see if wasm-gc is installed and if not install it - execSync('wasm-gc'); - } catch (err) { - execSync('cargo install wasm-gc', { stdio: 'inherit' }); - } finally { - // think of this like running --gc-sections on the app.wasm file - execSync('wasm-gc build/app.wasm', { stdio: 'inherit' }); - } } catch (error) { console.log(chalk.bold.red('error compiling rust')); } @@ -31,6 +22,11 @@ module.exports = { } }, installRustWebAssemblyTools: () => { + try { + execSync('cargo install wasm-gc', { stdio: 'inherit' }); + } catch { + console.log(`${chalk.bold.red('error installing wasm-gc')} please install manually ${chalk.red('cargo install wasm-gc')}')`); + } execSync( 'rustup target add wasm32-unknown-unknown --toolchain nightly', { stdio: 'inherit' } From 9b36ccf56fc843e59cfa101d824cfdd05ea6fe95 Mon Sep 17 00:00:00 2001 From: Thomas Horrobin Date: Sat, 27 Oct 2018 04:20:53 +0100 Subject: [PATCH 25/30] moved to using factorial as an example instead of add one --- packages/react-scripts/template/src/App.js | 5 +++-- packages/react-scripts/template/src/App.rs | 9 +++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/react-scripts/template/src/App.js b/packages/react-scripts/template/src/App.js index 94d371f6356..78d124c0f22 100644 --- a/packages/react-scripts/template/src/App.js +++ b/packages/react-scripts/template/src/App.js @@ -7,8 +7,9 @@ class App extends Component { constructor() { super(); loadWasm(result => { - const add_one = result.instance.exports['add_one']; - alert(`return value was ${add_one(3)}`); + const calculateFactorial = result.instance.exports['fact']; + const x = 5; + alert(`the factorial of ${ x } is ${ calculateFactorial(x) }`); }); } render() { diff --git a/packages/react-scripts/template/src/App.rs b/packages/react-scripts/template/src/App.rs index b3cd5c42148..6a732dde862 100644 --- a/packages/react-scripts/template/src/App.rs +++ b/packages/react-scripts/template/src/App.rs @@ -1,4 +1,9 @@ #[no_mangle] -pub extern "C" fn add_one(x: i32) -> i32 { - x + 1 +pub extern "C" fn fact(mut n: u32) -> u32 { + let mut result = 1; + while n > 0 { + result = result * n; + n = n - 1; + } + result } From f455b5172a0394080f29a047e2cecf9c9d1fe2a9 Mon Sep 17 00:00:00 2001 From: Thomas Horrobin Date: Sat, 27 Oct 2018 19:18:13 +0100 Subject: [PATCH 26/30] improved info on the splash page in the template added explicit note in app template reminding users they can save src/App.rs and have the app update automatically in the browser --- packages/react-scripts/template/src/App.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-scripts/template/src/App.js b/packages/react-scripts/template/src/App.js index 78d124c0f22..25c43654d1b 100644 --- a/packages/react-scripts/template/src/App.js +++ b/packages/react-scripts/template/src/App.js @@ -18,7 +18,7 @@ class App extends Component {
logo

- Edit src/App.js and save to reload. + Edit src/App.js or src/App.rs and save to reload.

Date: Sat, 27 Oct 2018 20:03:49 +0100 Subject: [PATCH 27/30] use command-exists instead of manually checking if cmd is avalible this commit replaces old code that was designed to determine if things like rustup or wasm-gc were installed the new implementation uses the npm package command-exists, which gives us better async, errs, etc --- packages/react-scripts/package.json | 1 + .../react-scripts/scripts/utils/rustUtils.js | 22 ++++++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index cc8a81cedcf..2d0af08e1e9 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -34,6 +34,7 @@ "babel-preset-react-app": "^7.0.1", "bfj": "6.1.1", "case-sensitive-paths-webpack-plugin": "2.2.0", + "command-exists": "^1.2.8", "css-loader": "1.0.0", "dotenv": "6.0.0", "dotenv-expand": "4.2.0", diff --git a/packages/react-scripts/scripts/utils/rustUtils.js b/packages/react-scripts/scripts/utils/rustUtils.js index 964d042c107..2525f24fa3e 100644 --- a/packages/react-scripts/scripts/utils/rustUtils.js +++ b/packages/react-scripts/scripts/utils/rustUtils.js @@ -1,5 +1,6 @@ const execSync = require('child_process').execSync; -const chalk = require('chalk'); +const chalk = require('react-dev-utils/chalk'); +const commandExistsSync = require('command-exists').sync; module.exports = { build: () => { @@ -13,19 +14,14 @@ module.exports = { console.log(chalk.bold.red('error compiling rust')); } }, - isRustInstalled: () => { - try { - execSync('rustup show'); - return true; - } catch (error) { - return false; - } - }, + isRustInstalled: () => commandExistsSync('rustup'), installRustWebAssemblyTools: () => { - try { - execSync('cargo install wasm-gc', { stdio: 'inherit' }); - } catch { - console.log(`${chalk.bold.red('error installing wasm-gc')} please install manually ${chalk.red('cargo install wasm-gc')}')`); + if (!commandExistsSync('wasm-gc')) { + try { + execSync('cargo install wasm-gc', { stdio: 'inherit' }); + } catch { + console.log(`${chalk.bold.red('error installing wasm-gc')} please install manually ${chalk.red('cargo install wasm-gc')}')`); + } } execSync( 'rustup target add wasm32-unknown-unknown --toolchain nightly', From c789c3e2040a34bf90e4d675572f6f74c2a38fab Mon Sep 17 00:00:00 2001 From: Thomas Horrobin Date: Sat, 27 Oct 2018 23:29:14 +0100 Subject: [PATCH 28/30] moved to using cargo init instead of copying Cargo.toml --- packages/react-scripts/package.json | 7 +++++++ packages/react-scripts/scripts/utils/rustUtils.js | 13 +++++++++++++ packages/react-scripts/template/Cargo.toml | 11 ----------- 3 files changed, 20 insertions(+), 11 deletions(-) delete mode 100644 packages/react-scripts/template/Cargo.toml diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index 2d0af08e1e9..91bb6355cf9 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -66,9 +66,16 @@ "resolve": "1.10.0", "rust-native-wasm-loader": "^0.8.1", "sass-loader": "7.1.0", +<<<<<<< HEAD "style-loader": "0.23.1", "terser-webpack-plugin": "1.2.2", "url-loader": "1.1.2", +======= + "style-loader": "0.23.0", + "terser-webpack-plugin": "1.1.0", + "toml-js": "0.0.8", + "url-loader": "1.1.1", +>>>>>>> moved to using cargo init instead of copying Cargo.toml "wasm-loader": "^1.3.0", "webpack": "4.28.3", "webpack-dev-server": "3.1.14", diff --git a/packages/react-scripts/scripts/utils/rustUtils.js b/packages/react-scripts/scripts/utils/rustUtils.js index 2525f24fa3e..37c71e39cea 100644 --- a/packages/react-scripts/scripts/utils/rustUtils.js +++ b/packages/react-scripts/scripts/utils/rustUtils.js @@ -1,6 +1,8 @@ const execSync = require('child_process').execSync; const chalk = require('react-dev-utils/chalk'); const commandExistsSync = require('command-exists').sync; +const fs = require('fs'); +const toml = require('toml-js'); module.exports = { build: () => { @@ -23,6 +25,17 @@ module.exports = { console.log(`${chalk.bold.red('error installing wasm-gc')} please install manually ${chalk.red('cargo install wasm-gc')}')`); } } + execSync( + 'cargo init --lib', + { stdio: 'inherit' } + ); + fs.readFile('Cargo.toml', function (err, data) { + var cargo = toml.parse(data); + cargo.lib = {}; + cargo.lib['crate-type'] = ['cdylib']; + cargo.lib.path = 'src/App.rs'; + fs.writeFile('Cargo.toml', toml.dump(cargo), err => console.log(err)); + }); execSync( 'rustup target add wasm32-unknown-unknown --toolchain nightly', { stdio: 'inherit' } diff --git a/packages/react-scripts/template/Cargo.toml b/packages/react-scripts/template/Cargo.toml deleted file mode 100644 index 5e91c518759..00000000000 --- a/packages/react-scripts/template/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "add" -version = "0.1.0" -authors = ["Thomas Horrobin "] -edition = "2018" - -[lib] -crate-type = ["cdylib"] -path = "src/App.rs" - -[dependencies] From 2ab41c698d841fff57d43a8b3d68f2e516de0440 Mon Sep 17 00:00:00 2001 From: Thomas Horrobin Date: Sat, 15 Dec 2018 10:05:10 +0000 Subject: [PATCH 29/30] modified logging --- packages/react-scripts/scripts/utils/rustUtils.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/react-scripts/scripts/utils/rustUtils.js b/packages/react-scripts/scripts/utils/rustUtils.js index 37c71e39cea..3e31c522c37 100644 --- a/packages/react-scripts/scripts/utils/rustUtils.js +++ b/packages/react-scripts/scripts/utils/rustUtils.js @@ -21,7 +21,8 @@ module.exports = { if (!commandExistsSync('wasm-gc')) { try { execSync('cargo install wasm-gc', { stdio: 'inherit' }); - } catch { + } catch (e) { + console.log(e); console.log(`${chalk.bold.red('error installing wasm-gc')} please install manually ${chalk.red('cargo install wasm-gc')}')`); } } From 3084f147c5a833a22cc1c20d46aab35f364bf4ea Mon Sep 17 00:00:00 2001 From: Bogdan Dumitru Date: Tue, 19 Feb 2019 12:05:39 +0700 Subject: [PATCH 30/30] Rebase artefact --- packages/react-scripts/package.json | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index 91bb6355cf9..87c6e13f3cd 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -1,6 +1,6 @@ { - "name": "react-scripts", - "version": "2.1.5", + "name": "@bowdo/react-scripts", + "version": "next", "description": "Configuration and scripts for Create React App.", "repository": "facebook/create-react-app", "license": "MIT", @@ -66,16 +66,10 @@ "resolve": "1.10.0", "rust-native-wasm-loader": "^0.8.1", "sass-loader": "7.1.0", -<<<<<<< HEAD "style-loader": "0.23.1", "terser-webpack-plugin": "1.2.2", - "url-loader": "1.1.2", -======= - "style-loader": "0.23.0", - "terser-webpack-plugin": "1.1.0", "toml-js": "0.0.8", - "url-loader": "1.1.1", ->>>>>>> moved to using cargo init instead of copying Cargo.toml + "url-loader": "1.1.2", "wasm-loader": "^1.3.0", "webpack": "4.28.3", "webpack-dev-server": "3.1.14",