from pathlib import Path import fcntl,hashlib,json,os,subprocess,time p=Path('');tree=p/'snapshots/c36-miri-selectors';out=p/'results/c36-local-checks.json' os.sched_setaffinity(0,set(range(16,32))) def digest(): h=hashlib.sha256() for f in sorted(tree.rglob('*.rs')): if '.git' not in f.parts and 'target' not in f.parts:h.update(str(f.relative_to(tree)).encode()+b'\0'+f.read_bytes()) for name in ['Cargo.toml','Cargo.lock','.cargo/config.toml']:h.update(name.encode()+b'\0'+(tree/name).read_bytes()) return h.hexdigest() def git(*args):return subprocess.check_output(['git','-c','gc.auto=0','-c','maintenance.auto=false',*args],cwd=tree,text=True).strip() base=dict(os.environ,CARGO_HOME='/tmp/sample-vsti-ci-cargo',CARGO_TARGET_DIR=str(p/'cargo-check'),CARGO_BUILD_JOBS='8',CARGO_INCREMENTAL='0',CARGO_PROFILE_DEV_DEBUG='0',CARGO_PROFILE_TEST_DEBUG='0',LIBRARY_PATH='/tmp/sample-vsti-x11/root/usr/lib/x86_64-linux-gnu',CARGO_TERM_COLOR='never',RUST_BACKTRACE='1') base.pop('RUSTFLAGS',None);base.pop('RUSTDOCFLAGS',None) winflags=['-C','target-feature=+crt-static','-C','linker=/usr/lib/llvm-19/bin/lld-link','-C','linker-flavor=lld-link','-C','link-arg=-nodefaultlib:ucrt','-C','link-arg=-defaultlib:libucrt','-C','link-arg=/ignore:4099'] for suffix in ['crt/lib/x86_64','sdk/lib/um/x86_64','sdk/lib/ucrt/x86_64']:winflags+=['-Lnative=/'+suffix] winenv=dict(base,RUSTFLAGS=' '.join(winflags),LD_LIBRARY_PATH='/usr/lib/x86_64-linux-gnu',CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_RUNNER=str(p/'c36-wine-test-runner.py'),WINEPREFIX=str(p/'wine-c36-local-tests'),WINESERVER=str(p/'profiling-tools/wine11/opt/wine-stable/bin/wineserver'),WINEDEBUG='-all',WINEDLLOVERRIDES='winemenubuilder.exe=d') common=['--locked','--workspace','--all-targets','--all-features'] jobs=[('fmt',['cargo','+stable','fmt','--all','--check'],False)] for toolchain in ['stable','1.95.0']: for profile in ['test','release']:jobs.append((f'linux-{toolchain}-{profile}',['cargo','+'+toolchain,'test','--profile',profile,*common],False)) for toolchain in ['stable','1.95.0']:jobs.append((f'windows-{toolchain}-test',['cargo','+'+toolchain,'test','--profile','test','--target=x86_64-pc-windows-msvc',*common],True)) jobs += [('linux-clippy',['cargo','+stable','clippy',*common,'--','-D','warnings'],False),('windows-clippy',['cargo','+stable','clippy','--target=x86_64-pc-windows-msvc',*common,'--','-D','warnings'],True),('linux-doc',['cargo','+stable','doc','--locked','--workspace','--all-features','--no-deps'],False)] with (p/'measurement.lock').open('a') as measurement: fcntl.flock(measurement,fcntl.LOCK_SH) record={'tree':str(tree),'commit':git('rev-parse','HEAD'),'source_sha256':digest(),'target_dir':str(p/'cargo-check'),'wine_prefix':str(p/'wine-c36-local-tests'),'jobs':[]} for name,command,windows in jobs: print('WAIT '+name,flush=True) with (p/'measurement.lock').open('a') as measurement,(p/'build.lock').open('a') as build: fcntl.flock(measurement,fcntl.LOCK_SH);fcntl.flock(build,fcntl.LOCK_EX) assert digest()==record['source_sha256'];(tree/'src/lib.rs').touch();env=dict(winenv if windows else base) if name=='linux-doc':env['RUSTDOCFLAGS']='-D warnings' logfile=p/f'results/c36-{name}.log';start=time.time_ns();print('RUN '+name,flush=True) with logfile.open('w') as log: log.write('commit='+record['commit']+'\nsource_sha256='+record['source_sha256']+'\ncommand='+repr(command)+'\n');log.flush() result=subprocess.run(command,cwd=tree,env=env,stdout=log,stderr=subprocess.STDOUT) if windows: subprocess.run([winenv['WINESERVER'],'-k'],env=env,check=False) subprocess.run([winenv['WINESERVER'],'-w'],env=env,check=False) finish=time.time_ns();assert digest()==record['source_sha256'] entry={'name':name,'command':command,'windows':windows,'start_unix_ns':start,'finish_unix_ns':finish,'elapsed_seconds':(finish-start)/1e9,'exit_code':result.returncode,'log':str(logfile.relative_to(p)),'log_sha256':hashlib.sha256(logfile.read_bytes()).hexdigest(),'source_sha256':digest()};record['jobs'].append(entry);out.write_text(json.dumps(record,indent=2)+'\n');print('DONE '+name+' '+str(result.returncode)+' '+str(entry['elapsed_seconds']),flush=True) if result.returncode:print(logfile.read_text()[-7000:],flush=True);raise SystemExit(result.returncode) print('ALL LOCAL CHECKS PASSED',flush=True)