Skip to content

Instantly share code, notes, and snippets.

@justin-himself
Last active December 21, 2022 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justin-himself/cb6babac66e95f62ecebf95d06b6b314 to your computer and use it in GitHub Desktop.
Save justin-himself/cb6babac66e95f62ecebf95d06b6b314 to your computer and use it in GitHub Desktop.
Install wasm for qt 5.15 on Apple M1

Install wasm for qt 5.15 on Apple M1

  1. Install Docker for Apple M1

  2. Pull docker image maukalinow/qtwasm_builder

    docker pull maukalinow/qtwasm_builder
    
  3. Compile cpp file below and move the binary to /usr/local/bin/qtwasm

FINISHIED!

Simply run qtwasm in your project folder and wait, everything would be done for you.

#define EMSDK_CACHE_PATH "~/.emsdk_cache"
#define QT_VERSION_TAG "5.15_latest"
/* Date: 2021-04-10
* Name: qtwasm_shell
* Author: me@justin.education
* License: CC-BY-SA-4.0
* https://creativecommons.org/licenses/by-sa/4.0/
* Notes: The program works with docker image [maukalinow/qtwasm_builder],
* to provide a human friendly command line interface.
*/
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
using namespace std;
#define MAX_PATH_LENGTH 512
#define ALLOC (char*)malloc(sizeof(char)*MAX_PATH_LENGTH)
void help(){
cout<<"Welcome to qtwasm_shell."<<endl;
cout<<"Usage: qtwasm [options] [path]"<<endl<<endl;
cout<<"-i, --input \t\t to specify source path, default is current path"<<endl;
cout<<"-o, --output \t\t to specify build path, default is {src}/build"<<endl;
cout<<"-h, --help \t\t to display this help"<<endl;
}
void exec(char* src, char* dest){
cout<<"Source folder: \t"<<src<<endl;
cout<<"Build folder: \t"<<dest<<endl;
char *buffer = (char*)malloc(sizeof(char)*(3*MAX_PATH_LENGTH+200));
memset(buffer,0,sizeof(buffer));
sprintf(buffer,"docker run --rm -v %s:/project/build -v %s:/project/source -v %s:/root/dev/emsdk/upstream/emscripten/cache maukalinow/qtwasm_builder:%s",
dest,src,EMSDK_CACHE_PATH,QT_VERSION_TAG);
cout<<buffer<<endl;
cout<<"========================="<<endl<<endl;
system(buffer);
}
char* rp(char* path){ //realpath
char* rpath = ALLOC;
if(realpath(path,rpath)==NULL){
cout<<"Invalid path: \t"<<path<<endl;
exit(1);
}
return rpath;
}
int main(int argc,char *argv[])
{
if(argc == 2)
if(!strcmp(argv[1],"-h")||!strcmp(argv[1],"--help")){
help();
exit(0);
}
//init
char *cwd = ALLOC, *src = ALLOC, *dest = ALLOC;
memset(cwd,0,sizeof(cwd));
memset(src,0,sizeof(src));
memset(dest,0,sizeof(dest));
if((cwd = getcwd(NULL, 0)) == NULL){
perror("getcwd error");
exit(1);
}
//search for arguments
for(int i=1;i<argc;i++){
if((!strcmp(argv[i],"-i") || !strcmp(argv[i],"--input"))
&& !strcmp(src,"") && i+1<argc){
strcpy(src,argv[++i]);
}else if((!strcmp(argv[i],"-o") || !strcmp(argv[i],"--output"))
&& !strcmp(dest,"") && i+1<argc)
strcpy(dest,argv[++i]);
else{
cout<<"Incorrect argument: \t"<<argv[i]<<endl;
cout<<"Use qtwasm -h to display help."<<endl;
exit(1);
}
}
//adjust for launch
if(!strcmp(src,"") && !strcmp(dest,""))
exec(cwd,strcat(rp(strcpy(dest,cwd)),"/build"));
else if(!strcmp(src,""))
exec(cwd,rp(dest));
else if(!strcmp(dest,"")){
if(*(src+strlen(src)-1)=='/')
*(src+strlen(src)-1)=0;
exec(rp(src),strcat(rp(strcpy(dest,src)),"/build"));
}else
exec(rp(src),rp(dest));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment