Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toolchain Management #181

Merged
merged 40 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
f4e774f
[cli] toolchain WIP
ZenVoich Nov 30, 2023
17a3626
[cli] toolchain: moc wrapper
ZenVoich Nov 30, 2023
6c35924
Merge branch 'main' into cli/toolchain
ZenVoich Dec 5, 2023
5fb2c66
[cli] toolchain: `pocket-ic` support
ZenVoich Dec 5, 2023
4e9d5e9
Merge branch 'main' into cli/toolchain
ZenVoich Dec 8, 2023
fc67494
[cli] toolchain: add `mops toolchain use` and `mops toolchain bin`
ZenVoich Dec 15, 2023
b860e64
Merge branch 'main' into cli/toolchain
ZenVoich Dec 15, 2023
40a5697
moc-wrapper.sh chmod +x
ZenVoich Dec 16, 2023
e58963a
[cli] toolchain WIP
ZenVoich Dec 16, 2023
7b7e09a
update `mops.lock`
ZenVoich Dec 18, 2023
ce03030
[cli] toolchain: add `mops toolchain init` and `mops toolchain reset`
ZenVoich Dec 18, 2023
67e612f
[cli] toolchain: add `mops toolchain update`; install toolchain on `m…
ZenVoich Dec 18, 2023
17279d5
[cli] toolchain: fix `mops toolchain update`
ZenVoich Dec 18, 2023
710039a
[cli] toolchain: fix wasmtime download
ZenVoich Dec 18, 2023
9f355e7
[cli] `mops bench --replica pocket-ic` use pocket-ic version specifie…
ZenVoich Dec 19, 2023
861e5e8
-
ZenVoich Dec 19, 2023
78794b2
[cli] toolchain: non-strict check if toolchain inited on `mops instal…
ZenVoich Dec 19, 2023
47d12fa
[cli] lockfile v2: check only deps hash instead of entire mops.toml hash
ZenVoich Dec 19, 2023
dc91026
[cli] `mops toolchain use` prompt tool version if not specified
ZenVoich Dec 20, 2023
36f25d9
[cli] use managed `moc`, `mo-doc`, `wasmtime` in commands `mops test`…
ZenVoich Dec 20, 2023
e0df809
[cli] `mops toolchain use` support `latest` tag
ZenVoich Dec 20, 2023
ed717f0
use wasmtime 13.0.0
ZenVoich Dec 20, 2023
a329eff
update CI config
ZenVoich Dec 20, 2023
c427307
fix CI
ZenVoich Dec 20, 2023
9d6a1da
fix CI
ZenVoich Dec 20, 2023
8199111
[cli] fix toolchain init in github actions
ZenVoich Dec 20, 2023
0e6f982
[cli] fix toolchain init in github actions
ZenVoich Dec 20, 2023
f8beb6a
update `moc` and `base` to 0.10.2
ZenVoich Dec 21, 2023
84bb872
replace `arrayTake` helper with `Array.take`
ZenVoich Dec 21, 2023
0466c34
[backend] remove extra imports
ZenVoich Dec 21, 2023
463e483
[cli] `mops test` add support for wasmtime >= 14.0.0
ZenVoich Dec 21, 2023
0f3b6b1
use wasmtime 16.0.0
ZenVoich Dec 21, 2023
989ac9b
[cli] `mops cache` support toolchain
ZenVoich Dec 21, 2023
893c85f
remove extra code
ZenVoich Dec 21, 2023
d8a3609
remove extra code
ZenVoich Dec 21, 2023
885a5f3
[cli] `mops install` pretty log on toolchain install
ZenVoich Dec 21, 2023
0ab7166
[cli] fix bug where cursor disappeared after some commands
ZenVoich Dec 21, 2023
bdba420
[backend] define category for `icrc1-mo` package
ZenVoich Dec 22, 2023
2d93600
[docs] add `mops toolchain` docs
ZenVoich Dec 22, 2023
6fee86b
[cli] add `--fallback` flag to `mops toolchain bin moc`
ZenVoich Dec 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ jobs:
max-parallel: 2
matrix:
moc-version: [0.10.1]
mops-version: [./cli, ic-mops@latest, [email protected]]
# mops-version: [./cli, ic-mops@latest, [email protected]]
mops-version: [./cli]
node-version: [20]

runs-on: ubuntu-latest
Expand All @@ -40,9 +41,6 @@ jobs:
path: |
~/.cache/mops

- name: Select moc version
run: npx mocv use ${{ matrix.moc-version }}

- name: Install npm packages
run: npm install

Expand All @@ -53,12 +51,12 @@ jobs:
- name: Install mops
run: npm i -g ${{ matrix.mops-version }}

- name: Install mocv
run: npm i -g mocv

- name: Install mops packages
run: mops install

- name: Select moc version
run: mops toolchain use moc ${{ matrix.moc-version }}

- name: Build and Deploy
run: |
npm run replica
Expand Down
15 changes: 5 additions & 10 deletions .github/workflows/mops-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ jobs:
strategy:
max-parallel: 3
matrix:
# mops-version: [./cli, ic-mops@latest, [email protected]]
moc-version: [0.10.1, latest]
mops-version: [./cli, ic-mops@latest, [email protected]]
mops-version: [./cli]
node-version: [18, 20]

runs-on: ubuntu-latest
Expand All @@ -26,12 +27,6 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: install wasmtime
run: |
curl https://wasmtime.dev/install.sh -sSf | bash
bash -ci "$(curl -fsSL https://wasmtime.dev/install.sh)" -- --version v13.0.0
echo "$HOME/.wasmtime/bin" >> $GITHUB_PATH

- name: Cache mops packages
uses: actions/cache@v3
with:
Expand All @@ -42,9 +37,6 @@ jobs:
path: |
~/.cache/mops

- name: Select moc version
run: npx mocv use ${{ matrix.moc-version }}

- name: Install npm packages
run: |
cd cli
Expand All @@ -60,5 +52,8 @@ jobs:
- name: Install mops packages
run: mops install

- name: Select moc version
run: mops toolchain use moc ${{ matrix.moc-version }}

- name: Run tests
run: mops test
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm test && (cd cli && npm run check)
npm test && (cd cli && npm run check)
2 changes: 1 addition & 1 deletion backend/main/DownloadLog.mo
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ module {
func _getTrend(snapshotsOpt : ?Buffer.Buffer<DownloadsSnapshot>, max : Nat) : [DownloadsSnapshot] {
switch (snapshotsOpt) {
case (?snapshots) {
Utils.arrayTake(Buffer.toArray(snapshots), -max);
Array.take(Buffer.toArray(snapshots), -max);
};
case (null) {
[];
Expand Down
18 changes: 1 addition & 17 deletions backend/main/main-canister.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,16 @@ import Text "mo:base/Text";
import Array "mo:base/Array";
import Buffer "mo:base/Buffer";
import TrieMap "mo:base/TrieMap";
import HashMap "mo:base/HashMap";
import Iter "mo:base/Iter";
import Time "mo:base/Time";
import Nat "mo:base/Nat";
import Int "mo:base/Int";
import Result "mo:base/Result";
import Debug "mo:base/Debug";
import Option "mo:base/Option";
import Principal "mo:base/Principal";
import Order "mo:base/Order";
import Char "mo:base/Char";
import Hash "mo:base/Hash";
import TrieSet "mo:base/TrieSet";
import ExperimentalCycles "mo:base/ExperimentalCycles";
import Blob "mo:base/Blob";
import Prim "mo:prim";

import {DAY} "mo:time-consts";
import {ic} "mo:ic";
import Map "mo:map/Map";
import Backup "mo:backup";
import Sha256 "mo:sha2/Sha256";
import HttpTypes "mo:http-types";
Expand All @@ -34,8 +24,6 @@ import StorageManager "../storage/storage-manager";
import Storage "../storage/storage-canister";
import Users "./Users";
import Badges "./badges";
import {validateConfig} "./utils/validateConfig";
import {generateId} "../generate-id";

import Registry "./registry/Registry";
import PackagePublisher "./PackagePublisher";
Expand Down Expand Up @@ -308,10 +296,6 @@ actor class Main() {
};
};

func _toLowerCase(text : Text) : Text {
Text.map(text, Prim.charToLower);
};

public query func search(searchText : Text.Text, limitOpt : ?Nat, pageIndexOpt : ?Nat) : async ([PackageSummary], PageCount) {
searchInRegistry(registry, users, downloadLog, searchText, limitOpt, pageIndexOpt);
};
Expand Down Expand Up @@ -413,7 +397,7 @@ actor class Main() {

packagesFirstPub.vals()
|> Iter.toArray(_)
|> Utils.arrayTake(_, 5)
|> Array.take(_, 5)
|> Array.reverse(_);
};

Expand Down
1 change: 1 addition & 0 deletions backend/main/registry/packagesByCategory.mo
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ module {
"icrc7-mo",
"icrc30-mo",
"icrc-nft-mo",
"icrc1-mo",
]
),
];
Expand Down
6 changes: 0 additions & 6 deletions backend/utils.mo
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,4 @@ module {
items.size() / limit + (if (items.size() % limit == 0) 0 else 1),
);
};

public func arrayTake<T>(ar : [T], n : Int) : [T] {
let resSize = Nat.min(Int.abs(n), ar.size());
let start : Nat = if (n > 0) 0 else ar.size() - resSize;
Array.subArray(ar, start, resSize);
};
}
3 changes: 3 additions & 0 deletions cli/bin/moc-wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
mocPath="$(mops toolchain bin moc --fallback)"
$mocPath "$@"
3 changes: 3 additions & 0 deletions cli/bin/mops.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node

import '../cli.js';
Binary file removed cli/bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions cli/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export let copyCache = (pkgId: string, dest: string) => {
};

export let cacheSize = async () => {
let dir = path.join(globalCacheDir, 'packages');
let dir = path.join(globalCacheDir);
fs.mkdirSync(dir, {recursive: true});

let size = await getFolderSize.strict(dir);
Expand All @@ -50,6 +50,6 @@ export let cacheSize = async () => {
};

export let cleanCache = async () => {
let dir = path.join(globalCacheDir, 'packages');
let dir = path.join(globalCacheDir);
fs.rmSync(dir, {recursive: true, force: true});
};
3 changes: 0 additions & 3 deletions cli/cli-local.ts

This file was deleted.

63 changes: 60 additions & 3 deletions cli/cli.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env node

import fs from 'node:fs';
import {program, Argument, Option} from 'commander';
import {Command, Argument, Option} from 'commander';
import chalk from 'chalk';

import {init} from './commands/init.js';
Expand All @@ -26,6 +24,8 @@ import {outdated} from './commands/outdated.js';
import {update} from './commands/update.js';
import {bench} from './commands/bench.js';
import {transferOwnership} from './commands/transfer-ownership.js';
import {toolchain} from './commands/toolchain/index.js';
import {Tool} from './types.js';
// import {docs} from './commands/docs.js';

declare global {
Expand All @@ -38,6 +38,7 @@ if (fs.existsSync(networkFile)) {
globalThis.MOPS_NETWORK = fs.readFileSync(networkFile).toString() || 'ic';
}

let program = new Command();

program.name('mops');

Expand Down Expand Up @@ -101,13 +102,16 @@ program
return;
}

await toolchain.ensureToolchainInited({strict: false});

if (pkg) {
// @deprecated
console.log(chalk.yellow('Consider using the \'mops add\' command to install a specific package.'));
await add(pkg, options);
}
else {
await installAll(options);
await toolchain.installAll(options);
}
});

Expand Down Expand Up @@ -166,6 +170,7 @@ program
process.exit(1);
}
await installAll({silent: true, lock: 'ignore'});
await toolchain.ensureToolchainInited({strict: false});
let sourcesArr = await sources(options);
console.log(sourcesArr.join('\n'));
});
Expand Down Expand Up @@ -328,4 +333,56 @@ program
await transferOwnership(toPrincipal);
});

// toolchain
const toolchainCommand = new Command('toolchain').description('Toolchain management');

toolchainCommand
.command('init')
.description('One-time initialization of toolchain management')
.action(async () => {
await toolchain.init();
});

toolchainCommand
.command('reset')
.description('Uninstall toolchain management')
.action(async () => {
await toolchain.init({reset: true});
});

toolchainCommand
.command('use')
.description('Install specified tool version and update mops.toml')
.addArgument(new Argument('<tool>').choices(['moc', 'wasmtime', 'pocket-ic']))
.addArgument(new Argument('[version]'))
.action(async (tool, version) => {
if (!checkConfigFile()) {
process.exit(1);
}
await toolchain.use(tool, version);
});

toolchainCommand
.command('update')
.description('Update specified tool or all tools to the latest version and update mops.toml')
.addArgument(new Argument('[tool]').choices(['moc', 'wasmtime', 'pocket-ic']))
.action(async (tool?: Tool) => {
if (!checkConfigFile()) {
process.exit(1);
}
await toolchain.update(tool);
});

toolchainCommand
.command('bin')
.description('Get path to the tool binary\n<tool> can be one of "moc", "wasmtime", "pocket-ic"')
.addArgument(new Argument('<tool>').choices(['moc', 'wasmtime', 'pocket-ic']))
.addOption(new Option('--fallback', 'Fallback to the moc that comes with dfx if moc is not specified in the [toolchain] section'))
.action(async (tool, options) => {
let bin = await toolchain.bin(tool, options);
console.log(bin);
});

program.addCommand(toolchainCommand);

program.parse();
4 changes: 3 additions & 1 deletion cli/commands/add.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'node:path';
import chalk from 'chalk';
import logUpdate from 'log-update';
import {createLogUpdate} from 'log-update';
import {checkConfigFile, getGithubCommit, parseGithubURL, readConfig, writeConfig} from '../mops.js';
import {getHighestVersion} from '../api/getHighestVersion.js';
import {installFromGithub} from '../vessel.js';
Expand Down Expand Up @@ -109,6 +109,8 @@ export async function add(name: string, {verbose = false, dev = false, lock}: Ad

writeConfig(config);

let logUpdate = createLogUpdate(process.stdout, {showCursor: true});

if (lock !== 'ignore') {
logUpdate('Checking integrity...');
}
Expand Down
8 changes: 5 additions & 3 deletions cli/commands/bench-replica.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import {execSync} from 'node:child_process';
import path from 'node:path';
import fs from 'node:fs';
import {execaCommand} from 'execa';
import {PocketIc} from '@hadronous/pic';
import {PocketIc} from 'pic-ic';
import {getRootDir} from '../mops.js';
import {createActor, idlFactory} from '../declarations/bench/index.js';
import {toolchain} from './toolchain/index.js';

export class BenchReplica {
type : 'dfx' | 'pocket-ic';
Expand All @@ -27,7 +28,8 @@ export class BenchReplica {
execSync('dfx start --background --clean --artificial-delay 0' + (this.verbose ? '' : ' -qqqq'), {cwd: dir, stdio: ['inherit', this.verbose ? 'inherit' : 'ignore', 'inherit']});
}
else {
this.pocketIc = await PocketIc.create();
let pocketIcBin = await toolchain.bin('pocket-ic');
this.pocketIc = await PocketIc.create(pocketIcBin);
}
}

Expand All @@ -37,7 +39,7 @@ export class BenchReplica {
execSync('dfx stop' + (this.verbose ? '' : ' -qqqq'), {cwd: dir, stdio: ['pipe', this.verbose ? 'inherit' : 'ignore', 'pipe']});
}
else if (this.pocketIc) {
this.pocketIc.tearDown();
await this.pocketIc.tearDown();
}
}

Expand Down
Loading